How to get values from connection string settings section?

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

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


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

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

Use it : GetConfigConnectionString("LogDbConnectionString");

Comments or Responses

Login to post response