ConfigurationManager can not be found in .NET 2.0 ?

Published on Monday, January 10, 2011

When we added something such as database Connection String in App.config file in .Net 2.0, we need to use the following 2 ways to get Connection String:

1: ConfigurationSettings.AppSettings[“WinTerminalDBConnString”]

But if you use this, your compiler will says “This method is obsolete, it has been replaced by ConfigurationManager.AppSettings”;

So you have to use the 2nd way, see below

2: connStr = ConfigurationManager.ConnectionStrings[“WinTerminalDBConnString”].ConnectionString

However, you might see “ConfigurationManager” can not be found when you compile, the reason is you have to add a Reference explicitly to the System.Configuration.DLL assembly for the ConfigurationManager and add a using directive for System.Configuration for the class to be available to you.

See below: