Edit

Share via


Integrate SQL database in Microsoft Fabric with Service Connector

This page shows supported authentication methods and clients, and shows sample code you can use to connect your apps to SQL database in Microsoft Fabric using Service Connector. This page also shows default environment variable names and values you get when you create the service connection.

Supported compute services

Service Connector can be used to connect the following compute services to SQL database in Fabric:

  • Azure App Service
  • Azure Container Apps
  • Azure Functions
  • Azure Kubernetes Service (AKS)

Supported authentication types and client types

The following table shows which combinations of authentication methods and clients are supported for connecting your compute service to SQL database in Fabric using Service Connector. A "Yes" indicates that the combination is supported, while a "No" indicates that it is not supported.

Client type System-assigned managed identity User-assigned managed identity Secret/connection string Service principal
.NET Yes Yes No No
Go Yes Yes No No
Java Yes Yes No No
Java - Spring Boot Yes Yes No No
Python Yes Yes No No
None Yes Yes No No

This table indicates that as per Fabric behavior, only authentication via managed identities is allowed.

The system-assigned managed identity and user-assigned managed identity methods are supported for .NET, Java, Java - Spring Boot, Python, Go, and None client types. These methods are not supported for any other types.

Important

Manual access sharing is currently required for complete onboarding. See Share access to SQL database in Fabric.

Default environment variable names or application properties and sample code

Refer to the connection details and sample code presented in the following tabs to connect compute services to SQL database in Fabric. For more information about naming conventions, check the Service Connector internals article.

Note

Although SQL database in Fabric is distinct from Azure SQL Database, you can connect to and query your SQL database in Fabric in all the same ways as Azure SQL Database. Learn more.

System-assigned managed identity

Default environment variable name Description Example value
FABRIC_SQL_CONNECTIONSTRING Azure SQL Database connection string Data Source=tcp:<Fabric-SQL-Identifier>.msit-database.fabric.microsoft.com,1433;Initial Catalog=<SQL-DB-name>-<Fabric-DB-Identifier>;Authentication=ActiveDirectoryManagedIdentity

Sample code

Outlined below are the steps and code snippets to connect to SQL database in Fabric using a system-assigned managed identity.

  1. Install dependencies.

    dotnet add package Microsoft.Data.SqlClient
    
  2. Retrieve the SQL database in Microsoft Fabric connection string from the environment variable added by Service Connector.

    using Microsoft.Data.SqlClient;
    
    string connectionString = 
        Environment.GetEnvironmentVariable("FABRIC_SQL_CONNECTIONSTRING")!;
    
    using var connection = new SqlConnection(connectionString);
    connection.Open();
    

    For more information, see Using Active Directory managed identity authentication.

For more information, see Connect to your SQL database in Microsoft Fabric.

User-assigned Managed Identity

Default environment variable name Description Example value
FABRIC_SQL_CONNECTIONSTRING Azure SQL Database connection string Data Source=tcp:<Fabric-SQL-Identifier>.msit-database.fabric.microsoft.com,1433;Initial Catalog=<SQL-DB-name>-<Fabric-DB-Identifier>;User ID=<msiClientId>;Authentication=ActiveDirectoryManagedIdentity

Sample code

Outlined below are the steps and code snippets to connect to SQL database in Fabric using a user-assigned managed identity.

  1. Install dependencies.

    dotnet add package Microsoft.Data.SqlClient
    
  2. Retrieve the SQL database in Microsoft Fabric connection string from the environment variable added by Service Connector.

    using Microsoft.Data.SqlClient;
    
    string connectionString = 
        Environment.GetEnvironmentVariable("FABRIC_SQL_CONNECTIONSTRING")!;
    
    using var connection = new SqlConnection(connectionString);
    connection.Open();
    

    For more information, see Using Active Directory managed identity authentication.

For more information, see Connect to your SQL database in Microsoft Fabric.

Share access to SQL database in Fabric

  1. Complete creating your service connection on the Cloud Shell, or on your local Azure CLI.

  2. Once your connection is created, open your compute service resource in the Azure portal, open the Service Connector menu, and locate your SQL database in Fabric service connection. Select SQL database to navigate to the Fabric portal.

    Screenshot of the Azure portal, selecting SQL Database link to navigate to the Fabric portal.

  3. On the Fabric portal, locate the Security tab and select Manage SQL security.

    Screenshot of the Fabric portal, selecting Manage SQL Security.

  4. Select the role db_ddladmin, then Manage access.

    Screenshot of the Fabric portal, selecting the db_ddladmin role, and then clicking Manage access.

  5. You should see the name of your system-assigned managed identity, and/or any user-assigned managed identities with a service connection to this SQL database in Fabric. Select Share database. If you do not see the Share database option, you do not need to continue with the remaining steps.

    Screenshot of the Fabric portal, viewing a list of groups added to the role, and clicking Share database.

  6. Enter and select the name of your newly created system-assigned managed identity, and/or any user-assigned managed identities as they appear on the Manage access pane. Add any other identities as needed. Select the Read all data using SQL database checkbox, then select Grant.

    Screenshot of the Fabric portal, typing in the names of any assigned managed identities, selecting Read all data using SQL database, and then clicking Grant.

  7. You're now ready to use your new service connection to SQL database in Fabric.

Next step

Refer to the following article to learn more about Service Connector.