Connect Power Apps Code Apps to Any Data Source — Dataverse, Azure SQL, SharePoint, Copilot Studio & More
A complete developer guide to connecting Power Apps Code apps to any data source: Dataverse, Azure SQL, SharePoint, Copilot Studio agents, table metadata and REST APIs. See how to add each data source with PAC CLI, what each supports, how to choose the right one, and Microsoft best practices.
Power Apps Code apps rarely live on a single data source. The Power Apps client library for code apps lets you securely connect to Dataverse, Azure SQL, SharePoint, Copilot Studio and REST APIs — all from one code app. This developer guide walks through connecting to each source with the Power Platform CLI (PAC CLI), what each one supports, how to choose the right one, and the Microsoft best practices that keep your apps secure and scalable. Integrate. Automate. Innovate.
Why connecting external data matters
Modern business apps combine data from many systems. Connecting external data gives your code apps better performance, stronger security, higher scalability and a better user experience — the foundation for dashboards, automation, self-service and AI-powered apps.
- Better performance — get the right data in the right way for faster apps.
- Stronger security — use secure connectors and enterprise-grade authentication.
- Higher scalability — handle more data and more users with confidence.
- Better UX — deliver real-time, accurate data for smarter experiences.
- Common use cases — operational dashboards, business process automation, employee self-service, document & content apps, and AI-powered applications.
How connecting to data works (PAC CLI)
Under the hood, every connector-based data source follows the same pattern with the Power Platform CLI. After you initialize the app with pac code init, you create a connection, add it as a data source, then call the generated service from your code. Adding a data source auto-generates a typed TypeScript model and service under src/generated — for example, an Office 365 Users source produces Office365UsersModel and Office365UsersService.
- Create & set up connections — in Power Apps at
make.powerapps.com, or directly from the CLI (preview). List them and copy each connection’s API name and connection ID withpac connection list— the API name is the-avalue. All connectors are supported except Excel Online (Business) and Excel Online (OneDrive). - Add a data source — for a nontabular source (like Office 365 Users) run
pac code add-data-source -a <apiName> -c <connectionId>. For a tabular source (SQL, SharePoint) also pass-t <table/list>and-d <dataset/site>. For a SQL stored procedure pass-d <dataset> -sp <procedure>. - Discover, delete & reference — explore with
pac code list-datasets,pac code list-tablesandpac code list-sql-stored-procedures; remove one withpac code delete-data-source -a <apiName> -ds <name>; and bind to a connection reference with-cr <logicalName> -s <solutionId>(CLI 1.51.1+) so the app is portable across Dev, Test and Prod. - Update & run — import the generated service, verify locally with
npm run dev, then publish withnpm run build | pac code push.
# Get each connection's API name + ID
pac connection list
# Nontabular (e.g. Office 365 Users)
pac code add-data-source -a shared_office365users -c <connectionId>
# Tabular — SQL (-t table, -d "server,database")
pac code add-data-source -a shared_sql -c <connectionId> -t "[dbo].[Assets]" -d "srv.database.windows.net,db"
# Tabular — SharePoint (-t list, -d site URL)
pac code add-data-source -a shared_sharepointonline -c <connectionId> -t "Travel Request" -d "https://contoso.sharepoint.com/sites/Travel"
# SQL stored procedure
pac code add-data-source -a shared_sql -c <connectionId> -d "srv.database.windows.net,db" -sp "[dbo].[GetRecordById]"
# Delete, or bind to a connection reference for ALM
pac code delete-data-source -a shared_sql -ds Assets
pac code add-data-source -a shared_sql -cr <connectionReference> -s <solutionId>
Heads up: if a connection’s schema changes, there’s no command to refresh the generated files — delete the data source and add it again. Connector names and table/list names are case-sensitive, so copy the exact values from the list command output.
Connect to Dataverse
Use the Power Apps client library to securely connect your code app to Microsoft Dataverse and perform powerful data operations with generated, strongly-typed models and services.
- Connect to your environment — use PAC CLI to connect to your target environment.
- Add Dataverse as a data source — run
pac code add-data-source -a dataverse -t <table-logical-name>. - Start building — generated models and services appear under
src/generated; import and use them in your code.
- Supported — add entities, retrieve formatted values, get table metadata, work with lookups, image/file upload & download (preview), full CRUD, and delegation (filter, sort, top, paging).
- You get — enterprise-grade security, rich relationships and business rules, auditing, offline support and deep Power Platform & Microsoft 365 integration.
- Not yet supported — polymorphic lookups, schema-definition CRUD, FetchXML, alternate keys, and deleting Dataverse data sources through PAC CLI.
Connect to Azure SQL
Connect your code app to Azure SQL Database and work with your existing enterprise data at scale — call stored procedures, run complex queries and return strongly-typed results.
- Why Azure SQL — work with existing data, scale with confidence, secure by design (Microsoft Entra ID), powerful queries, and cost-efficient serverless options.
- What you can do — call stored procedures securely, perform CRUD, execute complex queries, work with parameters, return typed models, and handle paging, filtering and sorting.
- How to connect — create the database (Entra-only auth) and a SQL Server connection, then add a table with
pac code add-data-source -a "shared_sql" -c <connectionId> -t "[dbo].[Table]" -d "server.database.windows.net,database"(add-spfor a stored procedure). Test withnpm run dev, thennpm run build | pac code push. - Best for — financial systems, reporting & analytics, manufacturing & operations, HR & payroll, and legacy system integration.
Connect to SharePoint
Use the Power Apps client library to connect to SharePoint lists and perform full CRUD operations with ease — inheriting Microsoft 365 security and permissions.
- Why SharePoint — quick to build, familiar interface, inherits Microsoft 365 security, and perfect for collaboration and internal solutions.
- How it works — add a list with
pac code add-data-source -a "shared_sharepointonline" -c <connectionId> -t "<List name>" -d "<site URL>"; generated models and services are created automatically for CRUD and referenced values. - Operations — Read all or single items, Create and Update items by mapping lookup/choice/person values, Delete by item Id, and get referenced entities for choice, lookup and person/group columns.
- Tip — when creating or updating, pass expanded objects for lookup, choice and person columns (not just IDs), and omit fields with
#from the payload.
Connect to Copilot Studio agents
Bring AI conversations into your code apps. Connect to Microsoft Copilot Studio agents and get intelligent responses in real time using the ExecuteCopilotAsyncV2 action.
- Prerequisites — an initialized code app, a published Copilot Studio agent, Power Apps CLI v1.50+, and a connection to your environment via PAC CLI.
- Connect — ensure or create a connection, add the connector with
pac code add-data-source -a "shared_microsoftcopilotstudio", publish your agent, and copy the agent name from Channels → Web app. - Invoke — call
CopilotStudioService.ExecuteCopilotAsyncV2with amessageandagentName; readresponse.data.lastResponsewhencompletedis true. - Troubleshooting — use the
ExecuteCopilotAsyncV2endpoint, check the environment connection, and watch for property-casing differences when parsing JSON responses.
Read table metadata
Retrieve Dataverse table (entity) metadata at runtime so your apps adapt to customizations and localization — no code changes needed.
- Why read metadata — build dynamic, metadata-driven apps, support localized labels, reduce hard-coded logic, and adapt to schema at runtime.
- How to — connect with PAC CLI, add the Dataverse table, import the generated service, then call
getMetadata()with the required options. - What you can retrieve — entity (table) info, columns (attributes), relationships, and localized labels for tables and columns.
- Best practices — cache metadata at app start, request only what you need, use the generated TypeScript types, and handle undefined values safely.
Choosing the right data source
Each data source serves a unique purpose. Choose the one that best fits your business scenario, data model and scalability needs — and remember you can combine several in one app.
- Dataverse — enterprise apps on the Power Platform; relational + NoSQL, full/partial offline, real-time.
- Azure SQL — large, complex SQL systems; relational, high scalability, no offline.
- SharePoint — documents and collaboration; lists & libraries, limited offline and real-time.
- Copilot Studio — AI conversational experiences; knowledge and topics, real-time responses.
- Custom APIs / others — external and specialized integrations; capabilities depend on the API.
Best practices (Microsoft recommendations)
Follow these best practices to build secure, scalable, high-performing code apps when connecting to external data sources.
- Authenticate securely — use Microsoft Entra ID, avoid secrets in code, and use environment variables or Key Vault.
- Follow least privilege — grant only what the app needs, avoid admin privileges, and audit access regularly.
- Minimize API calls — retrieve only what you need with
$select,$filterand$top, and reduce round trips. - Cache smartly — cache metadata and frequently used data in memory with expiration.
- Handle errors gracefully — use try/catch for API calls, show user-friendly messages, and log detailed errors.
- Use async operations — use async/await for non-blocking calls to improve responsiveness and prevent timeouts.
- Monitor & log — track API performance with Application Insights and act on issues proactively.
- Respect API limits & throttling — understand connector limits and retry with exponential backoff.
- Test, validate & document — test integrations, validate edge cases, and document endpoints and logic.
Build smarter — connect to any data source
With the Power Apps client library for code apps, you can connect to Dataverse, Azure SQL, SharePoint, Copilot Studio and more — unlocking endless possibilities to build powerful, intelligent solutions. One platform. Unlimited connections. Infinite possibilities.
- Build faster — leverage pre-built connectors and generated services.
- Stay secure & scale confidently — follow Microsoft best practices and grow with enterprise workloads.
- Deliver more value & empower everyone — automate processes, drive innovation, and help teams work smarter together.
- Next steps — explore the client library, connect your data sources, build intelligent solutions, and deploy and scale with confidence.
Connect the right data. Build the right app. Drive the right outcomes.
Keywords: Power Apps Code, connect data source, Dataverse, Azure SQL, SharePoint, Copilot Studio, table metadata, REST APIs, pac code add-data-source, PAC CLI, ExecuteCopilotAsyncV2, connectors, best practices, Power Platform.
Share this:
Learn Microsoft 365 with new tutorials every week
Subscribe on YouTube and follow on LinkedIn for hands-on Power Platform, SharePoint, Copilot Studio, and Microsoft 365 guides.
Related articles
- Power Apps Code — React Project Structure Explained (PAC CLI)A folder-by-folder, file-by-file tour of a Power Apps Code (React + Vite + TypeScript) project scaffolded by the PAC CLI. What .power, node_modules, public, src and generated are for, what App.tsx, main.tsx, package.json and power.config.json do, and which files to leave alone.
- What Is Microsoft Power Fx? The Low-Code Language of the Power PlatformA plain-English introduction to Microsoft Power Fx — the Excel-like, low-code language behind Power Apps and the wider Power Platform. What it is, why it "thinks spreadsheet", how declarative formulas auto-recalculate, the no-code to pro-code spectrum, its design principles, and where you use it.
- Install Developer Tools for Power Apps Code Apps — A Complete Setup Guide (PAC CLI)Set up your environment for Power Apps Code apps step by step: install the developer tools (VS Code, git, .NET, Node.js and the Power Platform CLI), enable code apps on your Power Platform environment, understand what PAC CLI does, compare installation options and OS support, verify your install, connect to an environment, and manage authentication profiles.