Reading Connection Strings in Web.Config and App.Config and Enterprise Library DAAB Settings

Reading All Connection Strings in App.Config or Web.Config

Actually, reading all the connection strings in the app.config or web.config is pretty easy now that we have the wonderful System.Configuration Namespace and its rich functionality. The code is pretty straight forward. We can read all the connection strings as well as each name, provider, etc:



ConnectionStringSettingsCollection connectionStrings =
ConfigurationManager.ConnectionStrings;

foreach (ConnectionStringSettings connection in connectionStrings)
{
string connectionStringName = connection.Name;
string connectionString = connection.ConnectionString;
string providerName = connection.ProviderName;

Debug.Print(connectionStringName);
}



reference : http://www.davidhayden.com/blog/dave/archive/2007/02/22/ReadConnectionStringsWebConfigAppConfig.aspx

Comments

Popular posts from this blog

Singleton pattern implementation in C#

DataSet vs DataView