blah blah blah is here! blah blah » Close

up0down
link

Hi,
I'm building a simple console application, so I added the connection string elements into my app.config file.
I now want to grab the connection string information using:
Console.WriteLine(ConfigurationManager.ConnectionStrings["SQLServer"].ConnectionString);
I added using System.Configuration to the .cs page.
It doesn't seem to be working? Is ConfigurationManager only available for web applications??

last answered 2 years ago

1 answers

up0down
link

You'll also need to add a reference to System.Configuration.dll to the project as it's not added by default.

up0down
link

ahhh...ok I forgot that.
I find it wierd, shouldn't VS.NET report an error if I forget to add the namespace to my references?

up0down
link

You should get a build error message on the followng lines:
The type or namespace 'ConfigurtionManager' could not be found (are you missing a using directive or assembly reference?).
But the big giveway with VS is if a class doesn't show up in intellisense as you type it in. You know then that something's wrong before you even build.

This post was imported from csharpfriends, if you have a similiar question please ask it again.

All previous members have been migrated, hope you enjoy the new platform!

Feedback