Config Issue

Topics: Data Access Application Block
Jul 23, 2008 at 8:10 PM
Hi,
I have a C# class library where I coded my DAL using Data Application Block(DAB) version 4. Inside my solution I also have a web application that references the DAL from that C# class library. What should I put in my web.config to make it work, the first time I run it, it throw an error:

Database db = DatabaseFactory.CreateDatabase();  this code is inside my class library which is being called from the web application.

in my C# class library i have app.config that generated by the Enterprise library tool:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </configSections>
  <dataConfiguration defaultDatabase="RFWebDataConnectionString" />
  <connectionStrings>
    <add name="MyConnectionString" connectionString="Data Source=DEVL;Initial Catalog=MyDB;User ID=myID_User;Password=xxx"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>

do I need to add something in my web.config to make this work?

thanks
Jul 23, 2008 at 9:13 PM
Hi,

You're trying to create the default database specified as RFWebDataConnectionString in the configuration file snippet you've provided, but there doesn't seem to be a connection string with  that name (although it could be inherited).

What does the actual error you get look like?

Fernando
Jul 24, 2008 at 1:20 PM
thanks for reply.
actually the app.config of my class library looks like this
<configuration>
  <configSections>
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </configSections>
  <dataConfiguration defaultDatabase="MyConnectionString" />
  <connectionStrings>
    <add name="MyConnectionString" connectionString="Data Source=DEVL;Initial Catalog=MyDB;User ID=myID_User;Password=xxx"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>

So the default db is referenced in my connection strings "MyConnectionString". If i build this class library project, it didn't give me any error. Once i reference this project in the Web Application Project, I got this error:

The value can not be null or an empty string.

Database db = DatabaseFactory.CreateDatabase();

This line of code is of course in my class library project. Do I need to put any thing from app.config of the class library project into my web.config?

thanks


Jul 24, 2008 at 1:41 PM

Hi,

As far as ASP.NET is concerned, the only source of configuration information is the web.config file; configuration files on library projects do not play any role when an application using the library is running.
You need to make the configuration required by the library assembly available in the web.config file. If you have collisions, like another library requires a different database, then you need to make sure each library uses accesses the required resources by name (i.e. don't rely on the default database.)

Fernando

Jul 24, 2008 at 8:50 PM
i added this part "<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />"
to my web.config. I got this error:
Parser Error Message: An error occurred creating the configuration section handler for dataConfiguration: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

i already referenced the Microsoft.Practices.EnterpriseLibrary.Data using add reference.
Jul 25, 2008 at 2:01 PM
Hi,

You need to make sure you've referenced a dll that matches the reference in the configuration file. You can search for the error code 0x80131040 in this forum for further details.

Fernando
Jul 25, 2008 at 7:29 PM
thanks again for replying.
I found somewhere that the issue could be because of version differences. I noticed that other class library I included is using version 3. I also remove the tokenkey in web.config. Now it works fine.

thanks