Home Asp.net Difference between appSettings and connectionStrings in Web.config

Difference between appSettings and connectionStrings in Web.config

95
0
Difference between appSettings and connectionStrings in Web.config
Difference between appSettings and connectionStrings in Web.config

In my previous tutorials, I’d explained the difference between dataset datareader dataadapter dataview in .net, difference between executereader executenonquery and executescalar, top 10+ oops concepts with an examples and other similar tutorials on difference, appSettings, connectionStrings here.

Now here in this tutorial, I’ll explain the main difference between appsettings and connectionstrings in asp.net with an example.

Difference Between appSettings and connectionStrings

I think everyone knows about Web.config file and how to use it in asp.net project. So basically, web.config file holds the information about web application configuration settings including connection string that will use by application server (IIS) to manage your website or web application to run globally.

To describe it, words never stop. You’re here to know the difference, right?
.
.
.
Yes, Ofcource!

So coming to the point,

Actually, appSettings and connectionStrings are two configuration sections in the web.config file to define your application settings.

1. appSettings

The appSettings section is used to add any key value pair that you can access from your application.

For example, if you’re using SMTP settings to send emails, you may define your SMTP settings in this section in form of key value pairs.

Checkout more details about appSettings section real usage here.

Note: You can get more details about appSettings Element here from Microsoft’s official website.

2. connectionStrings

The connectionStrings section is used to add your database connnection strings with its unique names.

Checkout more details about connectionStrings section real usage here.

Note: You can get more details about connectionStrings Element here from Microsoft’s official website.

You can add connectionstrings in appSettings section but the convention is to add it in connectionStrings section so that your web.config will be easier to read, maintain, and handle.

Conclusion

There is a fundamental difference between appsettings and connectionstrings, In .NET 2.0 and above a connectionString object is an XML node that has specific attributes to set and semantically it refers to a database connection string where as appSettings is just a user-defined key-value pair that allows you to set your application settings and it can be anything that will be used within your website.

If you separate your connection strings into the connectionStrings section, you could increase your security level by encrypting connection strings because they are sensitive items. You can easily read other section as plain text, so your configuration file will be easier to read, modify ad maintain.

So the real difference is that the latest config feature expects the connection strings to be in the connectionStrings section. Furthermore, both sections are designed and intended to use in some defined purpose but it totally depends on you how you will use them?

Previous articleGet Folder Files List and Export to CSV in .NET
Next articleHow to Get ConnectionString from Web.config in Asp.net?
Hi there, I am Mayank, the man behind Technical Mack. I started AspnetO with a motive to educate people on various programming languages ranging from beginners to expert level. Through this blog, I aim to provide more insightful content.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

9 + three =