2005-09-15

Everything you know is wrong

You know how to access the configuration file from a DotNet app, right? You use System.Configuration.ConfigurationSettings.AppSettings, which is a static property that you index with a string.

However, if you’ve been around .NET 2.0 a little and have seen lists of feature changes in ADO.NET, you’re aware that there is now special support for connection strings. Books and websites will both tell you not to use ConfigurationSettings.AppSettings for connection strings anymore. Instead, you should use ConfigurationSettings.ConnectionStrings. This is the preferred way and possibly the only way if you’re trying to do fancy things like encrypt your connection strings or make your application database independent using provider factories.

Attempting this in Whidbey Beta 2 may cause you to doubt your intelligence and waste entirely too much time Googling websites that all have the same dated information and searching in local assemblies.

Beta 2, it turns out, has moved the functionality to ConfigurationManager.ConnectionStrings. Use something like ConfigurationManager.ConnectionStrings[“myalias”].ConnectionString.

And that’s life on the bleeding edge.