Accessing web.config AppSetting

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#:
<appSettings>
  <add key="ConnectionString" value="server=[server];user id=[userid];password=[userpw];database=[DataBase];Connect Timeout=100;"/>
</appSettings>
 
String sqlConnStr = ConfigurationSettings.AppSettings.Get("ConnectionString");

Open in new window

LVL 1
nkishAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ChetOS82Commented:
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")
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nkishAuthor Commented:
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?


0
ChetOS82Commented:
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).
0
nkishAuthor Commented:
How do I check the reference versions?
0
nkishAuthor Commented:
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.

Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.