What is the best place to store Database connection string?
In Web.Config, you would add a key to the AppSettings Section:
<appSettings>
<add key="MyConnection" value="server=<ServerName>; uid=<Username>; pwd=<Password>; database=<DBName>" />
</appSettings>
Example:
<add key="ConnectionString" value= "Server=localhost;uid=sa;pwd=;database=northwind" />
Then, in your ASP.Net application - just refer to it like this:
Dim myConnection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings(ConnectionString))
<appSettings>
<add key="MyConnection" value="server=<ServerName>; uid=<Username>; pwd=<Password>; database=<DBName>" />
</appSettings>
Example:
<add key="ConnectionString" value= "Server=localhost;uid=sa;pwd=;database=northwind" />
Then, in your ASP.Net application - just refer to it like this:
Dim myConnection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings(ConnectionString))
Comments
Post a Comment