DatabaseProviderFactory Error (v3.1 vs v4.1)

Topics: Data Access Application Block
Dec 10, 2010 at 3:49 PM
Edited Dec 10, 2010 at 3:49 PM

We've recently moved over to version of the EnterpriseLibrary and I'm coming across an issue I can't seem to resolve.  I've searched high and lo for a solution but have found none at all.  So, if anyone can tell me what I'm doing wrong or point me in the right direction would really appreciate it.  Thanks!

Here is what my app.config file looks like:

<?xml version="1.0"?>
        <add name="Profile" providerName="System.Data.SqlClient" connectionString="Data Source=TestDB,21664;Initial Catalog=ProfileData_10;User Id=User1;Password=Pass1;" />

This call in v3.1 of the EnterpriseLibrary works:

private void Form1_Load(object sender, EventArgs e)
    FileConfigurationSource srcFile = new FileConfigurationSource("GenericSolution.exe.config");
    DatabaseProviderFactory provFactory = new DatabaseProviderFactory(srcFile);
    Database testDB = provFactory.Create("Profile");

This same call in v4.1 of the EnterpriseLibrary throws an error on the last line (provFactory.Create("Profile")):

 Message "The current build operation (build key Build Key[Microsoft.Practices.EnterpriseLibrary.Data.Database, Profile]) failed: Index was outside the bounds of the array. (Strategy type ConfiguredObjectStrategy, index 2)" string

at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)\r\n 

at Microsoft.Practices.ObjectBuilder2.Builder.BuildUp(IReadWriteLocator locator, ILifetimeContainer lifetime, IPolicyList policies, IStrategyChain strategies, Object buildKey, Object existing)\r\n 

at Microsoft.Practices.ObjectBuilder2.Builder.BuildUp[TTypeToBuild](IReadWriteLocator locator, ILifetimeContainer lifetime, IPolicyList policies, IStrategyChain strategies, Object buildKey, Object existing)\r\n 

at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUp[T](IReadWriteLocator locator, ILifetimeContainer lifetimeContainer, String id, IConfigurationSource configurationSource)\r\n 

at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUp[T](String id, IConfigurationSource configurationSource)\r\n 

at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.NameTypeFactoryBase`1.Create(String name)\r\n 

Dec 13, 2010 at 9:00 AM

I tried to reproduce your problem in Entlib 4.1 by using the code snippet provided, unfortunately it is working fine from my end. Wondering if something have been missed during the migration. Also, just curious with this line  "FileConfigurationSource srcFile = new FileConfigurationSource("GenericSolution.exe.config");", if the GenericSolution.exe.config is an external config file other than what your app has been generated (I'm assuming this is a Winforms app) and if using FileConfigurationSource is necessary. If this is just the same, then what I can also suggest is you can also instantiate the database object via the sample code below without the need of explicitly supplying the config file.

Database testDB = DatabaseFactory.CreateDatabase("Products");

As for the error encountered, can you also provide us the complete configuration used for us to further investigate.

Gino Terrado
Global Technologies and Solutions
Avanade, Inc.