Is there any difference between the following two lines of code in c# and app.config file.
C# connectionString declaration.
string conn = "/server = test/ DB = test_dev/ env = dev"
and
app.config declartion
<connectionStrings>
<add name="Test" connectionString="Data Source=.;Initial Catalog=test_dev;" providerName="System.Data.SqlClient" />
</connectionStrings>
How can I declare c# connection string to the format in the app.config file so that I can read from the app.config file.
There’s no real difference between hard coding a connection string and pulling one out of the app.config file.
The advantage of using app.config is that you can use that same connection string in multiple places in your application, and then if you need to change it (for testing purposes or anything else really), you only have to change it in one spot that is nicely contained in a configuration file.
As mentioned in the comments, to read a connection string directly from your app.config, you can use this:
although there are many different ways to access the connection string (DataSet, etc.)