Accessing web.config AppSetting

Posted on 2008-11-19
Last Modified: 2013-11-26
I'm looking access the AppSettings in the web.config file for use in the application.  I recently converted an application from 1.x to 3.5.

In 3.5 though, I get this Warning:
'System.Configuration.ConfigurationSettings.AppSettings' is obsolete: 'This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.AppSettings'

I've read on this site about using System.ConfigurationManager but for some reason, VS doesn't provide that as an option under System.

I'm using VS 9.0.30729.1 with SP 1.

Here's the 1.x code I'm using in the web.config and the C#:

  <add key="ConnectionString" value="server=[server];user id=[userid];password=[userpw];database=[DataBase];Connect Timeout=100;"/>


String sqlConnStr = ConfigurationSettings.AppSettings.Get("ConnectionString");

Open in new window

Question by:nkish
    LVL 18

    Accepted Solution

    System.Configuration.ConfigurationManager.AppSettings("ConnectionString") should work fine.

    You can also store that in the <connectionStrings> element (which works almost exactly like the appSettings element).  And then use System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString")
    LVL 1

    Author Comment

    Tried your suggestion, here's the Error I got:
    "The type or namespace name 'ConfigurationManager' does not exist in the namespace 'System.Configuration' (are you missing an assembly reference?)"

    I have "using System.Configuration;" in the references so I'm confused why its not seeing it.  Could there be something wrong in the setup?

    Also, I have VS 2005 and VS 2008 on the same machine... could there be anything there?

    Also, in the warning I'm getting in 3.5 saying what the replacement is, what does "System.Configuration!System.Configuration.ConfigurationManager.AppSettings'" mean?

    LVL 18

    Expert Comment

    Check your references and see if you have the 2.0 version of System.Configuration referenced (rather than 1.0 or 1.1).

    "System.Configuration!System.Configuration.ConfigurationManager.AppSettings" means that you are looking for the "System.Configuration.ConfigurationManager.AppSettings" in the "System.Configuration" assembly (that is, the System.Configuration.dll file).
    LVL 1

    Author Comment

    How do I check the reference versions?
    LVL 1

    Author Comment

    Never mind, I did some checking and found that I hadn't added the Reference of 'System.Configuration' as seen in the Solution Explorer.  I was just llooking at the 'Using' section of the C# code.  So, I checked your origional post and it's working okay now.


    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Flash ( has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
    Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now