Difference between appSettings and Connection Strings? [Resolved]

Posted by Amatya under .NET Framework on 2/18/2016 | Points: 10 | Views : 520 | Status : [Member] | Replies : 5
What is the Difference between appSettings and Connection Strings?

Feel free to share informations 9731764134
mail Id ' adityagupta200@gmail.com
Thanks



Responses

Posted by: Rajnilari2015 on: 2/18/2016 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
Both appears in the config file.

In the Connection Strings we specify the database connections e.g.


<connectionStrings>   

<add name="TestConnection" connectionString="Data Source=ServerName;Initial Catalog=DBName;User ID=LoginName;Password=DBPassword;"providerName="System.Data.SqlClient" />

</connectionStrings>


In appSettings section we specify the custom application settings e.g.

<appSettings>
<add key="SmtpUser" value="test@test.com" />
<add key="SmtpPassword" value="password" />
</appSettings>


Hope this helps

--
Thanks & Regards,
RNA Team

Amatya, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jitendrasoft09 on: 2/18/2016 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi,

appSettings is used to store general settings like server names, file paths, and other miscellaneous settings needed by an application but Connection Strings is used to store only database related settings.

Refer below link-
http://stackoverflow.com/questions/17603518/difference-between-connection-strings-in-app-settings-and-connectionstrings-conf

Jitendra Kumar
If my post helps you, plz mark as an answer.

Amatya, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Amatya on: 2/18/2016 [Member] Silver | Points: 25

Up
0
Down
What is Custom application settings.. However i can specify the database connections in appSetting, then what is actual use of Connection Strings?

Feel free to share informations 9731764134
mail Id ' adityagupta200@gmail.com
Thanks

Amatya, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajnilari2015 on: 2/18/2016 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 25

Up
0
Down
@Amatya,

The connectionString section gives strongly typed access to the connection strings through the ConfigurationManager class.

To read values from Connection strings

System.Configuration.ConfigurationManager.ConnectionStrings["TestConnection"].ConnectionString;


AppSettings is meant to store general/custom settings

To read values from AppSettings

System.Configuration.ConfigurationManager.AppSettings[key]


Though we can however store the values of database connections in AppSettings, but if you observe properly, you can find out that there is a specific element (providerName="System.Data.SqlClient") for it in connectionStrings

But app settings is only key-value pair type.

Please let us know if this clears the doubt.

Thanks

--
Thanks & Regards,
RNA Team

Amatya, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Amatya on: 2/18/2016 [Member] Silver | Points: 25

Up
0
Down
1 more question dude...
Can you give the Example of Key value pair examples in appSetting and where it helps and whats its use..

<appSettings>
<add key="SmtpUser" value="test@test.com" />
<add key="SmtpPassword" value="password" />
</appSettings>



You have provided the Example but what it is doing really ?

Thanks for you quick answers for my question :)

Feel free to share informations 9731764134
mail Id ' adityagupta200@gmail.com
Thanks

Amatya, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response