Connect Power Apps Code Apps to Any Data Source — Dataverse, Azure SQL, SharePoint, Copilot Studio & More

Suresh Girinathuni8 min read
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.

Why connecting external data matters for Power Apps Code apps: Dataverse, Azure SQL, SharePoint, Copilot Studio and REST APIs, the benefits, and common use cases
  • 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.

How to connect a Power Apps Code app to data with PAC CLI: create connections, add tabular and nontabular data sources with pac code add-data-source, discover, delete and use connection references, plus run and push commands
  1. 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 with pac connection list — the API name is the -a value. All connectors are supported except Excel Online (Business) and Excel Online (OneDrive).
  2. 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>.
  3. Discover, delete & reference — explore with pac code list-datasets, pac code list-tables and pac code list-sql-stored-procedures; remove one with pac 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.
  4. Update & run — import the generated service, verify locally with npm run dev, then publish with npm 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 a Power Apps Code app to Dataverse: how-to steps, pac code add-data-source, supported scenarios, what you get, and what is currently not supported
  1. Connect to your environment — use PAC CLI to connect to your target environment.
  2. Add Dataverse as a data source — run pac code add-data-source -a dataverse -t <table-logical-name>.
  3. 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.

Connect a Power Apps Code app to Azure SQL: why Azure SQL, what you can do, the five setup steps with pac code add-data-source, and best use cases
  • 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 -sp for a stored procedure). Test with npm run dev, then npm 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.

Connect a Power Apps Code app to SharePoint: why SharePoint, supported scenarios, how it works, and read/create/update/delete/referenced-entities operations
  • 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.
  • OperationsRead 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.

Connect a Power Apps Code app to Copilot Studio agents: prerequisites, five connection steps, the ExecuteCopilotAsyncV2 invoke code, and troubleshooting
  • 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.ExecuteCopilotAsyncV2 with a message and agentName; read response.data.lastResponse when completed is true.
  • Troubleshooting — use the ExecuteCopilotAsyncV2 endpoint, 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.

Read Dataverse table metadata in a Power Apps Code app: why read metadata, how to get it, the getMetadata() signature, and what you can retrieve
  • 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.

Choosing the right data source for Power Apps Code apps: a comparison of Dataverse, Azure SQL, SharePoint, Copilot Studio and Custom APIs across best-for, benefits, data model, scalability, offline and real-time
  • 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.

Microsoft best practices for connecting Power Apps Code apps to data: authenticate securely, least privilege, minimize API calls, cache smartly, handle errors, use async, monitor, respect limits, and test/validate/document
  1. Authenticate securely — use Microsoft Entra ID, avoid secrets in code, and use environment variables or Key Vault.
  2. Follow least privilege — grant only what the app needs, avoid admin privileges, and audit access regularly.
  3. Minimize API calls — retrieve only what you need with $select, $filter and $top, and reduce round trips.
  4. Cache smartly — cache metadata and frequently used data in memory with expiration.
  5. Handle errors gracefully — use try/catch for API calls, show user-friendly messages, and log detailed errors.
  6. Use async operations — use async/await for non-blocking calls to improve responsiveness and prevent timeouts.
  7. Monitor & log — track API performance with Application Insights and act on issues proactively.
  8. Respect API limits & throttling — understand connector limits and retry with exponential backoff.
  9. 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 smarter Power Apps Code apps: build faster, stay secure, scale confidently, deliver more value and empower everyone, with next steps and a connect-to-any-data-source code example
  • 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:

#Power Apps Code#PAC CLI#Dataverse#Azure SQL#SharePoint#Copilot Studio#Data Sources#Power Platform#Connectors#Pro-Code#Best Practices#Microsoft 365

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