What is the best place to store Database connection string in .Net?

In Web.Config, you would add a key to the AppSettings Section:


<add key="MyDBConnection" value="data source=<ServerName>;Initial catalog =<DBName>;user id=<Username>;password=<Password>;" />



<add key="ConnectionString" value= "data source=localhost;Initial catalog=northwind;user id=sa;password=mypass" />

Then, in your ASP.Net application - just refer to it like this:

using System.Configuration;

string connectionString = (string )ConfigurationSettings.AppSettings["ConnectionString"];

No comments:

Most Recent Post

Most Recent Ado.net FAQ

Most Recent .Net Framework FAQ

Most Recent Configuration Files FAQ

Daily Quote, Inspiration, Motivation and More

Subscribe Blog via Email

Enter your email address: