• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6691
  • Last Modified:

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

0
nkish
Asked:
nkish
  • 3
  • 2
1 Solution
 
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
 
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now