C# - Get connection string from Web.config file

2016/06/23 19:32

To get the connection string from the Web config file with CSharp code include the following using directive:
using System.Configuration;

Then create a string variable and assign the connection string like this:

string connStr = ConfigurationManager.ConnectionStrings["connectionString_Name"].ConnectionString;

If “ConfigurationManager” is not recognized you will need to add reference to: "System.Configuration".

See: “C# - How to add reference to project”.