Get specific connection string from App.Config file using C# (.NET)
The connection string can be retrieved from the App.Config file using ConnectionStrings method of ConfigurationManager. You need to add the following directive in the code:
using System.Configuration;
The ConnectionStrings method without any arguments will return a collection of Connection strings in the App.Config file. If you want to retrieve specific ones you can either pass an index or string to it
private static string retsettings(String sConnName)
{
try
{
ConnectionStringSettings sConnection = ConfigurationManager.ConnectionStrings[sConnName];
return sConnection.ConnectionString;
}
catch (Exception ex1)
{
return null;
}
finally
{ }
}
No comments:
Post a Comment