Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between appSettings and connectionStrings in Web.config file?

Tags:

asp.net

Why is there another section called connectionStrings? I have always just used appSettings, until I noticed this in a new project:

<appSettings>
 <add key="SqlConnString" value="server=ABC;database=ABC;uid=A;pwd=B;"/>
</appSettings>

<connectionStrings>    
</connectionStrings>

Is there a difference? Any reason why I should use one over the other?

like image 633
Neil N Avatar asked Aug 25 '09 18:08

Neil N


2 Answers

From the documentation:

The connectionStrings element specifies a collection of database connection strings, as name/value pairs, for ASP.NET applications and features.

In previous versions of ASP.NET, connection strings were stored in the appSettings. In ASP.NET 2.0, features, such as Session, Membership, Personalization, and Role Manager, rely on connection strings that are stored in the connectionStrings element. You can also use the connectionStrings element to store connection strings for your own applications.

So the only real difference is that the baked-in ASP.NET 2.0 features will expect their connection strings to be in the connectionStrings area.

like image 148
Eric Petroelje Avatar answered Oct 24 '22 03:10

Eric Petroelje


If you separate your connection strings into the <connectionStrings> section, your config will be easier to read, maintain, and handle.

Also, furthermore, you could increase your security by encrypting just the connection strings since those typically are the sensitive items, and if they're in their own section, you can easily just encrypt that one section and leave the rest of your app.config in plain text, so you can easily update and modify settings.

Marc

like image 22
marc_s Avatar answered Oct 24 '22 04:10

marc_s