sql connection string code example
Example 1: sql server connection string
Standard Security
Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;
Trusted Connection
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;
Connection to a SQL Server instance
The server/instance name syntax used in the server option is the same for all SQL Server connection strings.
Server=myServerName\myInstanceName;Database=myDataBase;User Id=myUsername;Password=myPassword;
Using a non-standard port
If your SQL Server listens on a non-default port you can specify that using the servername,xxxx syntax (note the comma, it's not a colon).
Server=myServerName,myPortNumber;Database=myDataBase;User Id=myUsername;Password=myPassword;
The default SQL Server port is 1433 and there is no need to specify that in the connection string.
Example 2: sql server conection string
Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;
Example 3: sql server provider name connection string
providerName="System.Data.SqlClient"
Example 4: ssms connect with connection string
Given the connection string:
Data Source=tcp:xxxxxxx.database.windows.net,1433;Initial Catalog=DatabaseName;User ID=zzzzz@xxxxxxx;Password=aaaaaa;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;Application Name=YourAppName;
Connection screen shot
Server name: xxxxxxx.database.windows.net,1433 "xxxxxxx" represents the server name
Login: zzzzz@xxxxxxx "zzzzz" represents your username, and "xxxxxxx" the server name
Password: aaaaaa represents your real password