configurationManager does not exist in the namespace System.Configuration

Go to references, and add a reference to System.Configuration

Once you have done this, you should be able to reference System.Configuration.ConfigurationManager.

string str = System.Configuration.ConfigurationManager.AppSettings["myconnection"];
SqlConnection oconnection = new SqlConnection(str);
oconnection.Open();

From MSDN:
The ConfigurationManager class enables you to access machine, application, and user configuration information. This class replaces the ConfigurationSettings class, which is deprecated.

http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.aspx


Edit: Addiitonal Information

In reference to the InvalidOperationException. This is caused when the connection string does not specify a data source or server. I am guessing that your connection string is empty.

In your web.config check the location of your connection string. If it falls under the element, then you will need to change your code to search ConnectionStrings and not AppSettings.

string str = System.Configuration.ConfigurationManager.
    ConnectionStrings["myconnection"].ConnectionString;

Leave a Comment