Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

App.Config ConnectionStrings

Status
Not open for further replies.

Elegabalus

Programmer
Jan 13, 2005
71
CA
I've got a class library that I use as the data access component of a web application in .NET 2.0.

I'm having trouble getting the connectionString information from the file, though.

When I hard code the connectionString into a string, it works fine.

When I try to get the value from the config file, it throws a null reference exception. Essentially, the code isn't getting the value from the config file.

I've added a manual reference to System.Configuration (as many posts on google mention is necessary). The following is the code I'm using to access the connectionString ("test" is the correct name of the key)

Code:
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["test"].ConnectionString;

Has anyone ever come across this before? I've tried the exact same code in a web application, and it works fine.

Any help is appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top