ASP.NET: Storing connection strings in the web.config file
From Wiki
Summary: Storing connection strings in the web.config file
Rather than writing out the connection string in your ASP.NET code behind files, you should store it in your web.config file so that it is easier to modify and store.
To add it to your config file, add it to the connectionString section:
- <connectionStrings>
- <add name="MyConnection" providerName="System.Data.SqlClient" connectionString="server=myserver;database=mydb;uid=username;pwd=password;"/>
- </connectionStrings>
You can then retrieve it via the ConfigurationManager class e.g
- ConfigurationManager.ConnectionStrings("myConnection").ConnectionString
This Hack is part of the ASP.NET Hacks collection


