Reputation: 4692
How do I read a value from the web.config file for a connectionstring in the 4.5 .net framework?
I'm using system.configuration which I have a reference to and a using statement, but the only thing coming up after that to use is .ConfigurationSettings.Appsettings
.
No connectionstringsettings.
Upvotes: 10
Views: 19967
Reputation: 70718
using System.Configuration;
string connectionString = ConfigurationManager.ConnectionStrings["StringName"].ConnectionString;
Edit (Adding in a reference to System.Configuration
:
Right click on your project -> Add Reference -> Select the .NET
Tab -> Select System.Configuration -> OK
http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.aspx
Upvotes: 15