C# – How to read a connectionstring in .net 4.5

cconnection-stringnetvb.netweb.config

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.

Best Answer

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