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.
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 |
Default environment variable name |
Description |
Sample value |
FABRIC_SQL_CONNECTIONSTRING |
Azure SQL Database connection string |
jdbc:sqlserver://<Fabric-SQL-Identifier>.msit-database.fabric.microsoft.com,1433;databaseName=<SQL-DB-name>-<Fabric-DB-Identifier>;authentication=ActiveDirectoryMSI; |
Default environment variable name |
Description |
Sample value |
FABRIC_SQL_CONNECTIONSTRING |
Azure SQL Database connection string |
jdbc:sqlserver://<Fabric-SQL-Identifier>.msit-database.fabric.microsoft.com,1433;databaseName=<SQL-DB-name>-<Fabric-DB-Identifier>;authentication=ActiveDirectoryMSI; |
Default environment variable name |
Description |
Example value |
FABRIC_SQL_CONNECTIONSTRING |
Azure SQL Database connection string |
Driver={ODBC Driver 17 for SQL Server};Server=tcp:<Fabric-SQL-Identifier>.msit-database.fabric.microsoft.com,1433;Database=<SQL-DB-name>-<Fabric-DB-Identifier>;Authentication=ActiveDirectoryMSI; |
Default environment variable name |
Description |
Example value |
FABRIC_SQL_CONNECTIONSTRING |
Azure SQL Database connection string |
server=tcp:<Fabric-SQL-Identifier>.msit-database.fabric.microsoft.com;port=1433;database=<SQL-DB-name>-<Fabric-DB-Identifier>;fedauth=ActiveDirectoryManagedIdentity; |
Default environment variable name |
Description |
Example value |
FABRIC_SQL_CONNECTIONSTRING |
Azure SQL Database connection string |
server=tcp:<Fabric-SQL-Identifier>.msit-database.fabric.microsoft.com;port=1433;database=<SQL-DB-name>-<Fabric-DB-Identifier>;fedauth=ActiveDirectoryManagedIdentity; |
Sample code
Outlined below are the steps and code snippets to connect to SQL database in Fabric using a system-assigned managed identity.
Install dependencies.
dotnet add package Microsoft.Data.SqlClient
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.
Add the following dependencies in your pom.xml file:
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>10.2.0.jre11</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.7.0</version>
</dependency>
Retrieve the SQL database in Microsoft Fabric connection string from the environment variable added by Service Connector.
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import com.microsoft.sqlserver.jdbc.SQLServerDataSource;
public class Main {
public static void main(String[] args) {
// FABRIC_SQL_CONNECTIONSTRING should be one of the following:
// For system-assigned managed identity: "jdbc:sqlserver://<Fabric-SQL-Identifier>.msit-database.fabric.microsoft.com,1433;databaseName=<SQL-DB-name>-<Fabric-DB-Identifier>;authentication=ActiveDirectoryMSI;"
// For user-assigned managed identity: "jdbc:sqlserver://<Fabric-SQL-Identifier>.msit-database.fabric.microsoft.com,1433;databaseName=<SQL-DB-name>-<Fabric-DB-Identifier>;msiClientId=<msiClientId>;authentication=ActiveDirectoryMSI;"
String connectionString = System.getenv("FABRIC_SQL_CONNECTIONSTRING");
SQLServerDataSource ds = new SQLServerDataSource();
ds.setURL(connectionString);
try (Connection connection = ds.getConnection()) {
System.out.println("Connected successfully.");
} catch (SQLException e) {
e.printStackTrace();
}
}
}
For more information, see Connect to Azure databases from App Service without secrets using a managed identity.
For a Spring application, if you create a connection with option --client-type springboot
, Service Connector sets the environment variable FABRIC_SQL_CONNECTIONSTRING
with value format jdbc:sqlserver://<Fabric-SQL-Identifier>.msit-database.fabric.microsoft.com,1433;databaseName=<SQL-DB-name>-<Fabric-DB-Identifier>;authentication=ActiveDirectoryMSI;
to Azure Spring Apps.
For user-assigned managed identities, msiClientId=<msiClientId>;
is added.
Update your application following the tutorial Migrate a Java application to use passwordless connections with Azure SQL Database. Remember to remove the spring.datasource.password
configuration property if it was previously set and add the correct dependencies.
spring:
datasource:
url: ${FABRIC_SQL_CONNECTIONSTRING}
Install dependencies.
python -m pip install pyodbc
Retrieve the SQL database in Microsoft Fabric connection string from the environment variable added by Service Connector. If you are using Azure Container Apps as compute service or the connection string in the code snippet doesn't work, refer to Migrate a Python application to use passwordless connections with Azure SQL Database to connect to SQL database in Microsoft Fabric using passwordless credentials. Authentication=ActiveDirectoryMSI;
is required in the connection string when connecting using managed identities. UID=<msiClientId>
is also required in the connection string when connecting using a user-assigned managed identity.
import os
import pyodbc, struct
from azure.identity import DefaultAzureCredential
connStr = os.getenv('FABRIC_SQL_CONNECTIONSTRING')
# System-assigned managed identity connection string format
# `Driver={ODBC Driver 17 for SQL Server};Server=tcp:<Fabric-SQL-Identifier>.msit-database.fabric.microsoft.com,1433;Database=<SQL-DB-name>-<Fabric-DB-Identifier>;Authentication=ActiveDirectoryMSI;`
# User-assigned managed identity connection string format
# `Driver={ODBC Driver 17 for SQL Server};Server=tcp:<Fabric-SQL-Identifier>.msit-database.fabric.microsoft.com,1433;Database=<SQL-DB-name>-<Fabric-DB-Identifier>;UID=<msiClientId>;Authentication=ActiveDirectoryMSI;`
conn = pyodbc.connect(connString)
- Install dependencies.
go mod init <YourProjectName>
go mod tidy
- Retrieve the SQL database in Microsoft Fabric connection string from the environment variable added by Service Connector.
package main
import (
"github.com/microsoft/go-mssqldb/azuread"
"database/sql"
"context"
"log"
"fmt"
"os"
)
var db *sql.DB
var connectionString = os.Getenv("FABRIC_SQL_CONNECTIONSTRING")
func main() {
var err error
// Create connection pool
db, err = sql.Open(azuread.DriverName, connectionString)
if err != nil {
log.Fatal("Error creating connection pool: ", err.Error())
}
ctx := context.Background()
err = db.PingContext(ctx)
if err != nil {
log.Fatal(err.Error())
}
fmt.Printf("Connected!\n")
}
For more information, see Use Golang to query a database in Azure SQL Database.
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 |
Default environment variable name |
Description |
Sample value |
FABRIC_SQL_CONNECTIONSTRING |
Azure SQL Database connection string |
jdbc:sqlserver://<Fabric-SQL-Identifier>.msit-database.fabric.microsoft.com,1433;databaseName=<SQL-DB-name>-<Fabric-DB-Identifier>;msiClientId=<msiClientId>;authentication=ActiveDirectoryMSI; |
Default environment variable name |
Description |
Sample value |
FABRIC_SQL_CONNECTIONSTRING |
Azure SQL Database connection string |
jdbc:sqlserver://<Fabric-SQL-Identifier>.msit-database.fabric.microsoft.com,1433;databaseName=<SQL-DB-name>-<Fabric-DB-Identifier>;msiClientId=<msiClientId>;authentication=ActiveDirectoryMSI; |
Default environment variable name |
Description |
Example value |
FABRIC_SQL_CONNECTIONSTRING |
Azure SQL Database connection string |
Driver={ODBC Driver 17 for SQL Server};Server=tcp:<Fabric-SQL-Identifier>.msit-database.fabric.microsoft.com,1433;Database=<SQL-DB-name>-<Fabric-DB-Identifier>;UID=<msiClientId>;Authentication=ActiveDirectoryMSI; |
Default environment variable name |
Description |
Example value |
FABRIC_SQL_CONNECTIONSTRING |
Azure SQL Database connection string |
server=tcp:<Fabric-SQL-Identifier>.msit-database.fabric.microsoft.com;port=1433;database=<SQL-DB-name>-<Fabric-DB-Identifier>;user id=<msiClientId>;fedauth=ActiveDirectoryManagedIdentity; |
Default environment variable name |
Description |
Example value |
FABRIC_SQL_CONNECTIONSTRING |
Azure SQL Database connection string |
server=tcp:<Fabric-SQL-Identifier>.msit-database.fabric.microsoft.com;port=1433;database=<SQL-DB-name>-<Fabric-DB-Identifier>;user id=<msiClientId>;fedauth=ActiveDirectoryManagedIdentity; |
Sample code
Outlined below are the steps and code snippets to connect to SQL database in Fabric using a user-assigned managed identity.
Install dependencies.
dotnet add package Microsoft.Data.SqlClient
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.
Add the following dependencies in your pom.xml file:
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>10.2.0.jre11</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.7.0</version>
</dependency>
Retrieve the SQL database in Microsoft Fabric connection string from the environment variable added by Service Connector.
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import com.microsoft.sqlserver.jdbc.SQLServerDataSource;
public class Main {
public static void main(String[] args) {
// FABRIC_SQL_CONNECTIONSTRING should be one of the following:
// For system-assigned managed identity: "jdbc:sqlserver://<Fabric-SQL-Identifier>.msit-database.fabric.microsoft.com,1433;databaseName=<SQL-DB-name>-<Fabric-DB-Identifier>;authentication=ActiveDirectoryMSI;"
// For user-assigned managed identity: "jdbc:sqlserver://<Fabric-SQL-Identifier>.msit-database.fabric.microsoft.com,1433;databaseName=<SQL-DB-name>-<Fabric-DB-Identifier>;msiClientId=<msiClientId>;authentication=ActiveDirectoryMSI;"
String connectionString = System.getenv("FABRIC_SQL_CONNECTIONSTRING");
SQLServerDataSource ds = new SQLServerDataSource();
ds.setURL(connectionString);
try (Connection connection = ds.getConnection()) {
System.out.println("Connected successfully.");
} catch (SQLException e) {
e.printStackTrace();
}
}
}
For more information, see Connect to Azure databases from App Service without secrets using a managed identity.
For a Spring application, if you create a connection with option --client-type springboot
, Service Connector sets the environment variable FABRIC_SQL_CONNECTIONSTRING
with value format jdbc:sqlserver://<Fabric-SQL-Identifier>.msit-database.fabric.microsoft.com,1433;databaseName=<SQL-DB-name>-<Fabric-DB-Identifier>;authentication=ActiveDirectoryMSI;
to Azure Spring Apps.
For user-assigned managed identities, msiClientId=<msiClientId>;
is added.
Update your application following the tutorial Migrate a Java application to use passwordless connections with Azure SQL Database. Remember to remove the spring.datasource.password
configuration property if it was previously set and add the correct dependencies.
spring:
datasource:
url: ${FABRIC_SQL_CONNECTIONSTRING}
Install dependencies.
python -m pip install pyodbc
Retrieve the SQL database in Microsoft Fabric connection string from the environment variable added by Service Connector. If you are using Azure Container Apps as compute service or the connection string in the code snippet doesn't work, refer to Migrate a Python application to use passwordless connections with Azure SQL Database to connect to SQL database in Microsoft Fabric using passwordless credentials. Authentication=ActiveDirectoryMSI;
is required in the connection string when connecting using managed identities. UID=<msiClientId>
is also required in the connection string when connecting using a user-assigned managed identity.
import os
import pyodbc, struct
from azure.identity import DefaultAzureCredential
connStr = os.getenv('FABRIC_SQL_CONNECTIONSTRING')
# System-assigned managed identity connection string format
# `Driver={ODBC Driver 17 for SQL Server};Server=tcp:<Fabric-SQL-Identifier>.msit-database.fabric.microsoft.com,1433;Database=<SQL-DB-name>-<Fabric-DB-Identifier>;Authentication=ActiveDirectoryMSI;`
# User-assigned managed identity connection string format
# `Driver={ODBC Driver 17 for SQL Server};Server=tcp:<Fabric-SQL-Identifier>.msit-database.fabric.microsoft.com,1433;Database=<SQL-DB-name>-<Fabric-DB-Identifier>;UID=<msiClientId>;Authentication=ActiveDirectoryMSI;`
conn = pyodbc.connect(connString)
- Install dependencies.
go mod init <YourProjectName>
go mod tidy
- Retrieve the SQL database in Microsoft Fabric connection string from the environment variable added by Service Connector.
package main
import (
"github.com/microsoft/go-mssqldb/azuread"
"database/sql"
"context"
"log"
"fmt"
"os"
)
var db *sql.DB
var connectionString = os.Getenv("FABRIC_SQL_CONNECTIONSTRING")
func main() {
var err error
// Create connection pool
db, err = sql.Open(azuread.DriverName, connectionString)
if err != nil {
log.Fatal("Error creating connection pool: ", err.Error())
}
ctx := context.Background()
err = db.PingContext(ctx)
if err != nil {
log.Fatal(err.Error())
}
fmt.Printf("Connected!\n")
}
For more information, see Use Golang to query a database in Azure SQL Database.
For more information, see Connect to your SQL database in Microsoft Fabric.
Share access to SQL database in Fabric
Complete creating your service connection on the Cloud Shell, or on your local Azure CLI.
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.
On the Fabric portal, locate the Security tab and select Manage SQL security.
Select the role db_ddladmin, then Manage access.
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.
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.
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.