For a long time I used:
ConfigurationManager.ConnectionStrings["sqlconnectionstring"].ConnectionString
to get the connection string from the app.config file
<configuration>
<connectionStrings>
<add name="sqlconnectionstring" connectionString="Data Source=ggg;Initial Catalog =DB;User ID=sa;Password=sa" />
</connectionStrings>
</configuration>
Lately I found that I canget the string using
global::myProj.Properties.Settings.Default.sqlconnectionstring;
- What is the difference?
- Can I access a key under appSetting?
- How come I don’t need to import System.Configuration?
Thanks Asaf
The
global::myProj.Properties.Settings.Default.sqlconnectionstring;stuff is generated by the settings designer in Visual Studio.The settings can be found in the solution explorer under Properties->Settings.settings, typesafe wrapper methods are automatically generated for all your properties defined in the settings designer.
This only works for settings defined in the settings designer (connection strings are automatically added to the settings designer).
Edit, to answer your specific questions