Azure SQL Database Connection String

In this article, I’ll share everything you need about Azure SQL Database connection strings to ensure your applications connect securely and efficiently.

Azure SQL Database Connection String

We need the Azure SQL Connection String from our local Visual Studio to connect to the Azure SQL Database in the cloud. We need to specify the connection strings in the config file to connect to the Azure SQL Database.

Provider System.Data.SqlClient

Standard

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <connectionStrings>
        <add name="MynewConnection"
             connectionString="Server=tcp:YourServerName.database.windows.net,1433;Initial Catalog=YourInitialCatalogName;User ID={YourUserName};Password={YourPassword};Encrypt=True;TrustServerCertificate=False;Connection Timeout=30"
             providerName="System.Data.SqlClient" />
    </connectionStrings>
</configuration>
azure sql database connection string c#

MARS enabled

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <connectionStrings>
        <add name="MynewConnection"
             connectionString="Server=tcp:YourServerName.database.windows.net,1433;Initial Catalog=YourInitialCatalogName;User ID={YourUserName};Password={YourPassword};Encrypt=True;Trusted_Connection=False;MultipleActiveResultSets=True;Connection Timeout=30"
             providerName="System.Data.SqlClient" />
    </connectionStrings>
</configuration>
azure sql database connection string

Azure AD Identity With Windows Authentication

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <connectionStrings>
        <add name="MynewConnection"
              connectionString="Server=tcp:YourServerName.database.windows.net,1433;Authentication=Active Directory Integrated;Database=yourdatabasename"
             providerName="System.Data.SqlClient" />
    </connectionStrings>
</configuration>
sql server connection string

With Encrypted

<connectionStrings>
    <add name="MynewConnection"
         connectionString="Data Source=YourServerName;Initial Catalog=YourDBName;Integrated Security=true;Column Encryption Setting=enabled;" 
 providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>
azure sql db connection string

Connection String Formats for Different Programming Languages

ADO.NET Connection String

For .NET developers, the ADO.NET connection string is most common:

Server=tcp:{your_server}.database.windows.net,1433;Database={your_database};User ID={your_username};Password={your_password};Encrypt=true;Connection Timeout=30;

When working with .NET applications, you’ll use the Microsoft.Data.The sqlClient package has replaced the older system.Data.SqlClient for Azure SQL connections.

JDBC Connection String for Java

Java developers will use the JDBC format:

jdbc:sqlserver://{your_server}.database.windows.net:1433;database={your_database};user={your_username}@{your_server};password={your_password};encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;

ODBC Connection String

For applications using ODBC drivers:

Driver={ODBC Driver 18 for SQL Server};Server=tcp:{your_server}.database.windows.net,143

Connection Strings For .NET Framework Data Provider for SQL Server

Standard

connectionString="Server=tcp:YourServerName.database.windows.net,1433;Database=YourDataBaseName;User ID=YourUserID;Password=YourPassword;Trusted_Connection=False;Encrypt=True;

MARS enabled

connectionString="Server=tcp:YourServerName.database.windows.net,1433;Database=YourDataBaseName;User ID=YourUserID;Password=YourPassword;Trusted_Connection=False;Encrypt=True;MultipleActiveResultSets=True;

Azure AD Identity With Windows Authentication

connectionString="Server=tcp:YourServerName.database.windows.net,1433;Authentication=Active Directory Integrated;Database=YourdatabaseName;

With Encrypted

Data Source=YourServerName;Initial Catalog=YourInitialCatalogName;Integrated Security=true;Column Encryption Setting=enabled;

Connection Strings For OLE DB Driver for SQL Server

With SQL Authentication

Provider=MSOLEDBSQL;Data Source=YourServerName;Initial Catalog=YourInitialCatalog;Authentication=SQLPassword;User ID=YourUserName;Password=YourPassword;Use Encryption for Data=true;

Windows authentication with SSPI

Provider=MSOLEDBSQL;Data Source=YourServerName;Initial Catalog=YourInitialCatalog;Authentication=ActiveDirectoryIntegrated;Use Encryption for Data=true;

AAD integrated authentication

Provider=MSOLEDBSQL;Data Source=YourServerName;Initial Catalog=YourInitialCatalog;Authentication=ActiveDirectoryIntegrated;Use Encryption for Data=true;

So these are a few lists of Azure SQL Database Connection Strings.

Essential Connection String Parameters

Beyond the basics, these parameters can optimize your connection:

ParameterDescriptionRecommended Value
Connect TimeoutMax time (seconds) to wait for connection30
EncryptForces TLS encryptiontrue
TrustServerCertificateValidates server certificatefalse
ApplicationIntentRead-write or read-onlyReadWrite
MultipleActiveResultSetsEnable MARSfalse
Max Pool SizeMaximum connections in pool100

Security Best Practices for Connection Strings

Below are the best practices.

  • Never hardcode connection strings in your application source code
  • Use environment variables or secure configuration stores like Azure Key Vault
  • Implement the principle of least privilege for database users
  • Enable Always Encrypted for sensitive data columns
  • Regularly rotate database credentials

Conclusion

This Azure article discusses the Azure SQL database connection string. Thanks for reading this article !!!

You may also like the following articles below

Azure Virtual Machine

DOWNLOAD FREE AZURE VIRTUAL MACHINE PDF

Download our free 25+ page Azure Virtual Machine guide and master cloud deployment today!