C# - Get database connection string from Web.config file

2017/10/05 02:45

To get the database connection string from IIS Web.config file using C# code, include System.Configuration directive and then create a string variable to assign the connection string like this:
using System.Configuration;
string connStr = ConfigurationManager.
                  ConnectionStrings["connectionString_Name"].ConnectionString;
If “ConfigurationManager” is not recognized you will need to add reference to: "System.Configuration".