Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Community Wiki

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Navigation

Google Ads

ASP.NET: Storing connection strings in the web.config file

From Wiki

Jump to: navigation, search


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:

  1. <connectionStrings>
  2.     <add name="MyConnection" providerName="System.Data.SqlClient" connectionString="server=myserver;database=mydb;uid=username;pwd=password;"/>
  3. </connectionStrings>

You can then retrieve it via the ConfigurationManager class e.g

  1. ConfigurationManager.ConnectionStrings("myConnection").ConnectionString


This Hack is part of the ASP.NET Hacks collection

498 Rating: 2.3/5 (3 votes cast)