ConnectionStrings or appSettings in

ConnectionStrings or appSettings in

 Though you have shifted to 2.0 or later then why in your application you are still storing connection Strings in AppSettings ?

Here is sample code to access connectionStrings.

In web.config


<add connectionString="servr=.;uid=sa;password=pass;database=mydb" name="XYZConnectionString" providerName="System.Data.SqlClient"/>


In code behind you can access it like this.

string connection = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["XYZConnectionString"].ConnectionString;

Benifit of adding connectionString in connectionString section is, you will be able to configure your membership provider , custom provider and third party components.

To know which connction string to use for what DB provider, you can refer

Note*: If you are using Class Library project in your project and your library project needs to access connection string,
          you need to add refrence of System.Configuration in your class library project.



Tags: 2.0 step by step Membership Provider asp net image Interview Questions for 2 years or 3 years File HandlingWhat is web garden in Convert String To Convert Image To open new windowHack How To Write a Cookie and ReadListBox Binding csharp


My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.

I'm Satalaj.