Connection Strings

suggest change

A Connection String is a string that specifies information about a particular data source and how to go about connecting to it by storing credentials, locations, and other information.

Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;

Storing Your Connection String

Typically, a connection string will be stored within a configuration file (such as an app.config or web.config within ASP.NET applications). The following is an example of what a local connection might look like within one of these files :

<connectionStrings> 
   <add name="WidgetsContext" providerName="System.Data.SqlClient"  connectionString="Server=.\SQLEXPRESS;Database=Widgets;Integrated Security=True;"/> 
</connectionStrings>

<connectionStrings> 
   <add name="WidgetsContext" providerName="System.Data.SqlClient"  connectionString="Server=.\SQLEXPRESS;Database=Widgets;Integrated Security=SSPI;"/> 
</connectionStrings>

This lets the application read the connection string programmatically through WidgetsContext. Integrated Security=SSPI and Integrated Security=True mean the same thing for SqlClient. Prefer Integrated Security=SSPI: it also works with the OleDb provider, whereas Integrated Security=true throws when used with OleDb.

Different Connections for Different Providers

Each data provider (SQL Server, MySQL, Azure, and others) has its own connection-string syntax and properties. ConnectionStrings.com is an incredibly useful resource if you are unsure about what yours should look like.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents