How to get values from connection string settings section?

Posted by Niladri.Biswas under C# category on | Points: 40 | Views : 1770
Suppose we have

<add name="LogDbConnectionString" connectionString="user id=se_user;pwd=se_user_pw!;data\iisdevdb1,1515;initial catalog=mydb;"
providerName="System.Data.SqlClient" />

To get the value from "LogDbConnectionString", let us write the below code

public static string GetConfigConnectionString(string configKey)
return System.Configuration.ConfigurationManager.ConnectionStrings[configKey].ToString();
catch (Exception ex)
return string.Empty;

Use it : GetConfigConnectionString("LogDbConnectionString");

Comments or Responses

Login to post response