There was a problem loading the comments.

How to Build a SQL Server Connection String (with Examples)

Support Portal  »  Knowledgebase  »  Viewing Article

  Print

Quick answer: A SQL Server connection string tells your application where the database is and how to authenticate. For SQL authentication it looks like: Server=myserver,1433;Database=mydb;User Id=appuser;Password=secret;. For Windows authentication, replace the credentials with Integrated Security=true.

SQL Server authentication

Server=203.0.113.25,1433;Database=YourDatabase;User Id=appuser;Password=StrongPass123!;

The comma before 1433 specifies the port. Use this style when the app connects with a SQL login.

Windows authentication

Server=YOURSERVER\SQLEXPRESS;Database=YourDatabase;Integrated Security=true;

This uses the current Windows account and needs no password in the string.

Encryption

For connections over a network, add encryption:

Encrypt=True;TrustServerCertificate=True;

Use TrustServerCertificate only where a fully trusted certificate is not installed.

Frequently asked questions

Why do I get a "server not found" error?
Usually the server name or port is wrong, TCP/IP is disabled, or the firewall blocks the port. Confirm the instance name and that 1433 is open.

Named instance vs port?
Use Server=host\instance for a named instance, or host,port when connecting by port number.

Managed SQL Server on a SoftSys managed Windows VPS is configured for secure application connections out of the box.


Share via
Did you find this article useful?  

Related Articles

Tags

© Softsys Hosting