Connection strings for SQL pools in Azure Synapse

You can connect to a SQL pool in Azure Synapse with several different application protocols such as, ADO.NET, ODBC, PHP, and JDBC. Below are some examples of connections strings for each protocol. You can also use the Azure portal to build your connection string.

Important

Use Microsoft Entra authentication when possible. For more information, see Use Microsoft Entra authentication for authentication with Synapse SQL.

To build your connection string using the Azure portal, navigate to your SQL pool blade, under Essentials select Show database connection strings.

Sample ADO.NET connection string

This simple example uses SQL authentication, but Microsoft Entra authentication with ADO.NET is more secure and recommended.

Server=tcp:{your_server}.database.chinacloudapi.cn,1433;Database={your_database};User ID={your_user_name};Password={your_password_here};Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;

Sample ODBC connection string

This simple example uses SQL authentication, but Microsoft Entra authentication with ODBC is more secure and recommended.

Driver={SQL Server Native Client 11.0};Server=tcp:{your_server}.database.chinacloudapi.cn,1433;Database={your_database};Uid={your_user_name};Pwd={your_password_here};Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;

Sample PHP connection string

This simple example uses SQL authentication, but Microsoft Entra authentication with PHP is more secure and recommended.

Server: {your_server}.database.chinacloudapi.cn,1433 \r\nSQL Database: {your_database}\r\nUser Name: {your_user_name}\r\n\r\nPHP Data Objects(PDO) Sample Code:\r\n\r\ntry {\r\n   $conn = new PDO ( \"sqlsrv:server = tcp:{your_server}.database.chinacloudapi.cn,1433; Database = {your_database}\", \"{your_user_name}\", \"{your_password_here}\");\r\n    $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );\r\n}\r\ncatch ( PDOException $e ) {\r\n   print( \"Error connecting to SQL Server.\" );\r\n   die(print_r($e));\r\n}\r\n\rSQL Server Extension Sample Code:\r\n\r\n$connectionInfo = array(\"UID\" => \"{your_user_name}\", \"pwd\" => \"{your_password_here}\", \"Database\" => \"{your_database}\", \"LoginTimeout\" => 30, \"Encrypt\" => 1, \"TrustServerCertificate\" => 0);\r\n$serverName = \"tcp:{your_server}.database.chinacloudapi.cn,1433\";\r\n$conn = sqlsrv_connect($serverName, $connectionInfo);

Sample JDBC connection string

This simple example uses SQL authentication, but Microsoft Entra authentication with JDBC is more secure and recommended.

jdbc:sqlserver://yourserver.database.chinacloudapi.cn:1433;database=yourdatabase;user={your_user_name};password={your_password_here};encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.chinacloudapi.cn;loginTimeout=30;

Note

Consider setting the connection timeout to 300 seconds in order to allow the connection to survive short periods of unavailability.

To start querying your SQL pool with Visual Studio and other applications, see Query with Visual Studio.