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?
So coming to the point,
Actually, appSettings and connectionStrings are two configuration sections in the web.config file to define your application settings.
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.
The connectionStrings section is used to add your database connnection strings with its unique names.
Checkout more details about connectionStrings section real usage here.
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.
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?