.NET has supported a number of ways to store configuration settings for quite some time, which has led to a good deal of confusion. It doesn't help that the top three hits for a search for "Settings in C#" over on MSDN are ten years old (and many of the related questions [2] on this venerable site are also 6-7 years old). It is really hard to determine which of the early recommendations have since been deprecated.
In my project I have chosen to use ApplicationSettings
(as opposed to AppSettings
) because:
- That appears to be the current recommended approach on MSDN (and here).
- The
AppSettings
element appears to be deprecated as of .NET 4+* (topic is "no longer available"; but see "Other Versions" on that page.) [*Although, confusingly, the AppSettings Property is still supported] - I prefer to edit the settings in a designer tool, rather than an xml editor.
- I prefer strongly typed settings.
However, now I need to decide where to put my connection strings. The most current documentation on MSDN (and here on SO, as well as CP) still appears to recommend using the <connectionStrings>
section of the app.config
. But accessing this from the code requires the use of the old syntax, which I now consider obsolete along with appSettings. In other words, it makes no sense to read one part of the app.config
file with the old syntax:
ConfigurationManager.ConnectionStrings["MydDBConnName"];
and another part of the same file with the new syntax:
Properties.Settings.Default.myOtherSetting;
Plus, it prevents me from being able to edit the strings in the designer.
So bottom line: is there any reason not to standardize all my configuration settings (including the connection strings) in the ApplicationSettings
element?