EntLib 5.0, Where did DatabaseConfigurationView go?

Topics: Data Access Application Block, Enterprise Library Core
May 4, 2010 at 3:36 PM

I've been using the DatabaseConfigurationView and FileConfigurationSource classes to read connection strings from a separate file than app/web.config.  I moved to 5.0 and the DatabaseConfigurationView class seems to have been taken away and I haven't been able to find a replacement to reimplement my functionality.  Any help?

May 5, 2010 at 12:54 AM

I saw in their change log that the ConfigurationView classes have been removed. I didn't see any replacement for it so I just copied the code from the 4.1 version.


Jun 26, 2012 at 3:41 PM
Edited Jun 26, 2012 at 3:49 PM

HELP! How do I migrate the following 1.1 code to 5.0? Thanks!

DatabaseConfigurationView dcv = new DatabaseConfigurationView(new
ConfigurationContext(AppDomain.CurrentDomain.BaseDirectory + "Config\\dataConfiguration.config"));
InstanceDataCollection idc = dcv.GetDatabaseSettings().Instances; foreach (InstanceData data in idc) { var instanceName = data.Name;
Jun 27, 2012 at 8:36 AM

Enterprise Library 5 Database configuration uses the .NET connectionString settings.  dataConfiguration section is mainly used for setting the default database (and any encryption/protection settings).

So if you are just reading in the database configuration you could use something like:

    var config = new FileConfigurationSource(AppDomain.CurrentDomain.BaseDirectory + "Config\\dataConfiguration.config");

    var configSection = config.GetSection("connectionStrings") as ConnectionStringsSection;
    var connections = configSection.ConnectionStrings;

    foreach (ConnectionStringSettings connection in connections)
        string name = connection.Name;
        string provider = connection.ProviderName;
        string connectionString = connection.ConnectionString;

The dataConfiguration.config file would look something like:

<?xml version="1.0" encoding="utf-8" ?>
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
  <dataConfiguration defaultDatabase="MyConn2" />
  <add name="MyConn2" connectionString="abc" providerName="System.Data.SqlClient" />

If the connection strings are already located in an automatically loaded configuration file (e.g. app.config or web.config) then you could just access the information using     ConnectionStringSettingsCollection connections = ConfigurationManager.ConnectionStrings.

Randy Levy
Enterprise Library support engineer