Ent Library 3.1 and Interop

Topics: Data Access Application Block
Jan 21, 2009 at 4:00 PM
My solution has 2 projects, a C# class project that does all the database calls, which has a .config file for the ent library and database calls. The second is a vb.net interop user control that is calling the C# project.

Here is my issue:
  1. When I run the solution or from vb 6 using the user control I get: the requested database name is not defined in the config. Which I think it clearly is, and I have it set to the defaultDatabase.

Here is the code:
IConfigurationSource source = new FileConfigurationSource(@"my.config");

DatabaseProviderFactory factory = new DatabaseProviderFactory(source);

//this does not work - I get an error that the requested database name is not defined in the config.
Database
db = factory.Create("MyDBName");


Here is the config:

<?

 

xml version="1.0" encoding="utf-8"?>

 

<

 

configuration>

 

<

 

configSections>

 

<

 

section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

 

<

 

section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

 

</

 

configSections>

 

<

 

connectionStrings>

 

<

 

add name="MyDBName" connectionString="Data Source=database;Initial Catalog=catalog;Integrated Security=True;User Instance=False"

providerName="System.Data.SqlClient" />

 

</

 

connectionStrings>

 

<

 

dataConfiguration defaultDatabase="MyDBName"/>

 

<

 

enterpriseLibrary.ConfigurationSource selectedSource="systemSource">

 

<

 

sources>

 

<

 

add name="fileSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

filePath="my.config" />

 

<

 

add name="systemSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

 

</

 

sources>

 

</

 

enterpriseLibrary.ConfigurationSource>

 

</

 

configuration>

Thank you

 

Jan 21, 2009 at 8:55 PM
Here is the resolution that I found.

I added the following to the GAC and everything worked.

Microsoft.Practices.EnterpriseLibrary.Common
Microsoft.Practices.EnterpriseLibrary.Data
Microsoft.Practices.Objectbuilder
Jan 22, 2009 at 3:08 AM
Edited Jan 22, 2009 at 6:05 AM
Hi,

I just noticed that in your config that you have 2 configuration sources, the FileConfigurationSource and the SystemConfigurationSource, If I'm not mistaken, your data configuration is saved in the "my.config" which is defined in the FileConfigurationSource. But your ConfigurationSource is pointing to the SystemConfigurationSource and not the FileConfigurationSource which has the "my.config" [<enterpriseLibrary.ConfigurationSource selectedSource="systemSource">) ].
That's maybe the cause of the entlib not finding your database.


Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com