| title | Integrate Azure SQL Database with Service Connector |
|---|---|
| description | Learn how to integrate Azure SQL Database into your application with Service Connector by using the supported authentication methods and clients. |
| author | maud-lv |
| ms.author | malev |
| ms.service | service-connector |
| ms.topic | how-to |
| ms.custom | engagement-fy23 |
| ms.date | 02/02/2026 |
In this article, we cover the supported authentication methods and clients that you can use to connect your apps to Azure SQL Database using Service Connector. For each supported method, we provide sample code and describe the default environment variable names, values, and configuration obtained when creating a service connection.
Service Connector can be used to connect the following compute services to Azure SQL Database:
- Azure App Service
- Azure Container Apps
- Azure Functions
- Azure Kubernetes Service (AKS)
- Azure Spring Apps
The following table shows which combinations of authentication methods and clients are supported for connecting your compute service to Azure SQL Database using Service Connector. A Yes indicates that the combination is supported, while a No indicates that it isn't supported.
| Client type | System-assigned managed identity | User-assigned managed identity | Secret/connection string | Service principal |
|---|---|---|---|---|
| .NET | Yes | Yes | Yes | Yes |
| Go | No | No | Yes | No |
| Java | Yes | Yes | Yes | Yes |
| Java - Spring Boot | Yes | Yes | Yes | Yes |
| Node.js | Yes | Yes | Yes | Yes |
| PHP | No | No | Yes | No |
| Python | Yes | Yes | Yes | Yes |
| Python - Django | No | No | Yes | No |
| Ruby | No | No | Yes | No |
| None | Yes | Yes | Yes | Yes |
Note
System-assigned managed identity, user-assigned managed identity and service principal authentication is only supported on Azure CLI.
Use the following connection details to connect compute services to Azure SQL Database. For each example, replace the placeholder texts <sql-server>, <sql-database>, <sql-username>, and <sql-password> with your own server name, database name, user ID, and password. For more information about naming conventions, check the Service Connector internals article.
[!div class="mx-tdBreakAll"]
Default environment variable name Description Sample value AZURE_SQL_CONNECTIONSTRINGAzure SQL Database connection string Data Source=<sql-server>.database.windows.net,1433;Initial Catalog=<sql-database>;Authentication=ActiveDirectoryManagedIdentity
[!div class="mx-tdBreakAll"]
Default environment variable name Description Sample value AZURE_SQL_CONNECTIONSTRINGAzure SQL Database connection string jdbc:sqlserver://<sql-server>.database.windows.net:1433;databaseName=<sql-database>;authentication=ActiveDirectoryMSI;
[!div class="mx-tdBreakAll"]
Default environment variable name Description Sample value spring.datasource.urlAzure SQL Database datasource URL jdbc:sqlserver://<sql-server>.database.windows.net:1433;databaseName=<sql-db>;authentication=ActiveDirectoryMSI;
[!div class="mx-tdBreakAll"]
Default environment variable name Description Sample value AZURE_SQL_SERVERAzure SQL Database server <sql-server>.database.windows.netAZURE_SQL_PORTAzure SQL Database port 1433AZURE_SQL_DATABASEAzure SQL Database database <sql-database>AZURE_SQL_AUTHENTICATIONAzure SQL authentication ActiveDirectoryMsi
[!div class="mx-tdBreakAll"]
Default environment variable name Description Sample value AZURE_SQL_SERVERAzure SQL Database server <sql-server>.database.windows.netAZURE_SQL_PORTAzure SQL Database port 1433AZURE_SQL_DATABASEAzure SQL Database database <sql-database>AZURE_SQL_AUTHENTICATIONTYPEAzure SQL Database authentication type azure-active-directory-default
[!div class="mx-tdBreakAll"]
Default environment variable name Description Sample value AZURE_SQL_HOSTAzure SQL Database server <sql-server>.database.windows.netAZURE_SQL_PORTAzure SQL Database port 1433AZURE_SQL_DATABASEAzure SQL Database database <sql-database>AZURE_SQL_AUTHENTICATIONAzure SQL Database authentication type azure-active-directory-default
To connect to Azure SQL Database using a system-assigned managed identity, refer to the following steps and sample code. [!INCLUDE code sample for sql]
[!div class="mx-tdBreakAll"]
Default environment variable name Description Sample value AZURE_SQL_CONNECTIONSTRINGAzure SQL Database connection string Data Source=<sql-server>.database.windows.net,1433;Initial Catalog=<sql-database>;User ID=<identity-client-ID>;Authentication=ActiveDirectoryManagedIdentity
[!div class="mx-tdBreakAll"]
Default environment variable name Description Sample value AZURE_SQL_CONNECTIONSTRINGAzure SQL Database connection string jdbc:sqlserver://<sql-server>.database.windows.net:1433;databaseName=<sql-database>;msiClientId=<msiClientId>;authentication=ActiveDirectoryMSI;
[!div class="mx-tdBreakAll"]
Default environment variable name Description Sample value spring.datasource.urlAzure SQL Database datasource URL jdbc:sqlserver://<sql-server>.database.windows.net:1433;databaseName=<sql-db>;msiClientId=<msiClientId>;authentication=ActiveDirectoryMSI;
[!div class="mx-tdBreakAll"]
Default environment variable name Description Sample value AZURE_SQL_SERVERAzure SQL Database server <sql-server>.database.windows.netAZURE_SQL_PORTAzure SQL Database port 1433AZURE_SQL_DATABASEAzure SQL Database database <sql-database>AZURE_SQL_USERAzure SQL Database user Object (principal) IDAZURE_SQL_AUTHENTICATIONAzure SQL authentication ActiveDirectoryMsi
[!div class="mx-tdBreakAll"]
Default environment variable name Description Sample value AZURE_SQL_SERVERAzure SQL Database server <sql-server>.database.windows.netAZURE_SQL_PORTAzure SQL Database port 1433AZURE_SQL_DATABASEAzure SQL Database database <sql-database>AZURE_SQL_AUTHENTICATIONTYPEAzure SQL Database authentication type azure-active-directory-defaultAZURE_SQL_CLIENTIDAzure SQL Database client ID <identity-client-ID>
[!div class="mx-tdBreakAll"]
Default environment variable name Description Sample value AZURE_SQL_HOSTAzure SQL Database server <sql-server>.database.windows.netAZURE_SQL_PORTAzure SQL Database port 1433AZURE_SQL_DATABASEAzure SQL Database database <sql-database>AZURE_SQL_AUTHENTICATIONAzure SQL Database authentication type azure-active-directory-defaultAZURE_SQL_USERNAMEAzure SQL Database client ID <your Client ID>
To connect to Azure SQL Database using a user-assigned managed identity, refer to the following steps and sample code. [!INCLUDE code sample for sql]
Warning
Microsoft recommends that you use the most secure authentication flow available. The authentication flow described in this procedure requires a high degree of trust in the application, and carries risks that aren't present in other flows. You should only use this flow when other more secure flows, such as managed identities, aren't viable.
[!div class="mx-tdBreakAll"]
Default environment variable name Description Sample value AZURE_SQL_CONNECTIONSTRINGAzure SQL Database connection string Data Source=<sql-server>.database.windows.net,1433;Initial Catalog=<sql-database>;Password=<sql-password>
[!div class="mx-tdBreakAll"]
Default environment variable name Description Sample value AZURE_SQL_CONNECTIONSTRINGAzure SQL Database connection string jdbc:sqlserver://<sql-server>.database.windows.net:1433;databaseName=<sql-database>;user=<sql-username>;password=<sql-password>;
[!div class="mx-tdBreakAll"]
Default environment variable name Description Sample value spring.datasource.urlAzure SQL Database datasource URL jdbc:sqlserver://<sql-server>.database.windows.net:1433;databaseName=<sql-db>;spring.datasource.usernameAzure SQL Database datasource username <sql-user>spring.datasource.passwordAzure SQL Database datasource password <sql-password>
[!div class="mx-tdBreakAll"]
Default environment variable name Description Sample value AZURE_SQL_SERVERAzure SQL Database server <sql-server>.database.windows.netAZURE_SQL_PORTAzure SQL Database port 1433AZURE_SQL_DATABASEAzure SQL Database database <sql-database>AZURE_SQL_USERAzure SQL Database user <sql-username>AZURE_SQL_PASSWORDAzure SQL Database password <sql-password>
[!div class="mx-tdBreakAll"]
Default environment variable name Description Sample value AZURE_SQL_HOSTAzure SQL Database host <sql-server>.database.windows.netAZURE_SQL_PORTAzure SQL Database port 1433AZURE_SQL_NAMEAzure SQL Database name <sql-database>AZURE_SQL_USERAzure SQL Database user <sql-username>AZURE_SQL_PASSWORDAzure SQL Database password <sql-password>
[!div class="mx-tdBreakAll"]
Default environment variable name Description Sample value AZURE_SQL_CONNECTIONSTRINGAzure SQL Database connection string server=<sql-server>.database.windows.net;port=1433;database=<sql-database>;user id=<sql-username>;password=<sql-password>;
[!div class="mx-tdBreakAll"]
Default environment variable name Description Sample value AZURE_SQL_SERVERAzure SQL Database server <sql-server>.database.windows.netAZURE_SQL_PORTAzure SQL Database port 1433AZURE_SQL_DATABASEAzure SQL Database database <sql-database>AZURE_SQL_USERNAMEAzure SQL Database username <sql-username>AZURE_SQL_PASSWORDAzure SQL Database password <sql-password>
[!div class="mx-tdBreakAll"]
Default environment variable name Description Sample value AZURE_SQL_SERVERNAMEAzure SQL Database servername <sql-server>.database.windows.net,1433AZURE_SQL_DATABASEAzure SQL Database database <sql-database>AZURE_SQL_UIDAzure SQL Database unique identifier (UID) <sql-username>AZURE_SQL_PASSWORDAzure SQL Database password <sql-password>
[!div class="mx-tdBreakAll"]
Default environment variable name Description Sample value AZURE_SQL_HOSTAzure SQL Database host <sql-server>.database.windows.netAZURE_SQL_PORTAzure SQL Database port 1433AZURE_SQL_DATABASEAzure SQL Database database <sql-database>AZURE_SQL_USERNAMEAzure SQL Database username <sql-username>AZURE_SQL_PASSWORDAzure SQL Database password <sql-password>
[!div class="mx-tdBreakAll"]
Default environment variable name Description Sample value AZURE_SQL_HOSTAzure SQL Database host <sql-server>.database.windows.netAZURE_SQL_PORTAzure SQL Database port 1433AZURE_SQL_DATABASEAzure SQL Database database <sql-database>AZURE_SQL_USERNAMEAzure SQL Database username <sql-username>AZURE_SQL_PASSWORDAzure SQL Database password <sql-password>
To connect to Azure SQL Database using a connection string, refer to the following steps and sample code. [!INCLUDE code sample for sql]
[!div class="mx-tdBreakAll"]
Default environment variable name Description Example value AZURE_SQL_CLIENTIDYour client ID <client-ID>AZURE_SQL_CLIENTSECRETYour client secret <client-secret>AZURE_SQL_TENANTIDYour tenant ID <tenant-ID>AZURE_SQL_CONNECTIONSTRINGAzure SQL Database connection string Data Source=<sql-server>.database.windows.net,1433;Initial Catalog=<sql-database>;User ID=<client-Id>;Password=<client-secret>;Authentication=ActiveDirectoryServicePrincipal
[!div class="mx-tdBreakAll"]
Default environment variable name Description Sample value AZURE_SQL_CONNECTIONSTRINGAzure SQL Database connection string jdbc:sqlserver://<sql-server>.database.windows.net:1433;databaseName=<sql-database>;user=<client-Id>;password=<client-secret>;authentication=ActiveDirectoryServicePrincipal;
[!div class="mx-tdBreakAll"]
Default environment variable name Description Sample value spring.datasource.urlAzure SQL Database datasource URL jdbc:sqlserver://<sql-server>.database.windows.net:1433;databaseName=<sql-db>;authentication=ActiveDirectoryServicePrincipal;spring.datasource.usernameAzure SQL Database datasource username <client-Id>spring.datasource.passwordAzure SQL Database datasource password <client-Secret>
[!div class="mx-tdBreakAll"]
Default environment variable name Description Sample value AZURE_SQL_SERVERAzure SQL Database server <sql-server>.database.windows.netAZURE_SQL_PORTAzure SQL Database port 1433AZURE_SQL_DATABASEAzure SQL Database database <sql-database>AZURE_SQL_USERAzure SQL Database user your Client IdAZURE_SQL_AUTHENTICATIONAzure SQL authentication ActiveDirectoryServerPrincipalAZURE_SQL_PASSWORDAzure SQL Database password your Client Secret
[!div class="mx-tdBreakAll"]
Default environment variable name Description Sample value AZURE_SQL_SERVERAzure SQL Database server <sql-server>.database.windows.netAZURE_SQL_PORTAzure SQL Database port 1433AZURE_SQL_DATABASEAzure SQL Database database <sql-database>AZURE_SQL_AUTHENTICATIONTYPEAzure SQL Database authentication type azure-active-directory-defaultAZURE_SQL_CLIENTIDAzure SQL Database client ID <your Client ID>AZURE_SQL_CLIENTSECRETAzure SQL Database client Secret <your Client Secret >AZURE_SQL_TENANTIDAzure SQL Database Tenant ID <your Tenant ID>
[!div class="mx-tdBreakAll"]
Default environment variable name Description Sample value AZURE_SQL_HOSTAzure SQL Database server <sql-server>.database.windows.netAZURE_SQL_PORTAzure SQL Database port 1433AZURE_SQL_DATABASEAzure SQL Database database <sql-database>AZURE_SQL_AUTHENTICATIONAzure SQL Database authentication type azure-active-directory-defaultAZURE_SQL_USERNAMEAzure SQL Database client ID <your Client ID>AZURE_SQL_PASSWORDAzure SQL Database client Secret <your Client Secret >
To connect to Azure SQL Database using a service principal, refer to the following steps and sample code. [!INCLUDE code sample for sql]
To learn more about Service Connector, see the following tutorial.
[!div class="nextstepaction"] Learn about Service Connector concepts