get connection string from web.config c# code example

Example 1: get connectionstring from web config c#

// Add a using directive at the top of your code file    
using System.Configuration;

// Within the code body set your variable    
string cs = ConfigurationManager.ConnectionStrings["connectionStringName"].ConnectionString;

Example 2: c# how to get connection string from app config

var connectionString=ConfigurationManager.ConnectionStrings["CharityManagement"].ConnectionString;

Example 3: get connection string from web.config in c#

get connection string