The requested database is not defined in configuration

Topics: Data Access Application Block
Jan 9, 2009 at 8:08 AM
Hello,
I have a problem with the DAAB library that prevents a control from being viewed in design mode. After initial set up, it all works fine but as soon as I close the form and then reopen it, the internal wiring gets messed up and generates the below error.
There is a reference to BVB.dll in CarLot project and accessing data works without problem even though the form cannot be changed anymore.

RiskManager.cs file:
line 20: Database db = DatabaseFactory.CreateDatabase("CarLot");

App.config file:
<?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" />
  </configSections>
  <connectionStrings>
    <add name="CarLot" connectionString="Data Source=FJ4\SQLEXPRESS;Initial Catalog=CarLot;Integrated Security=SSPI;"
      providerName="System.Data.SqlClient" />
    <add name="someName.CarLot.Properties.Settings.CarLotConnectionString"
      connectionString="Data Source=FJ4\SQLEXPRESS;Initial Catalog=CarLot;Integrated Security=True" />
  </connectionStrings>
</configuration>



Error Message
----
at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseConfigurationView.ValidateConnectionStringSettings(String name, ConnectionStringSettings connectionStringSettings)
at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseConfigurationView.GetConnectionStringSettings(String name)
at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseCustomFactory.CreateObject(IBuilderContext context, String name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id)
at Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
at Microsoft.Practices.ObjectBuilder.SingletonStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
at Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfigurationNameMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id)
at Microsoft.Practices.ObjectBuilder.BuilderBase`1.DoBuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies)
at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies)
at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp[TTypeToBuild](IReadWriteLocator locator, String idToBuild, Object existing, PolicyList[] transientPolicies)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUp[T](IReadWriteLocator locator, String id, IConfigurationSource configurationSource)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUp[T](String id, IConfigurationSource configurationSource)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.NameTypeFactoryBase`1.Create(String name)
at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseFactory.CreateDatabase(String name)
at BVB.RiskManager..ctor() in C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\CarLot\BVB\RiskManager.cs:line 20
at Baychev.CarLot.ucPerformanceSummary.UpdateData() in C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\CarLot\CarLot\ucPerformanceSummary.cs:line 36
at Baychev.CarLot.ucPerformanceSummary..ctor() in C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\CarLot\CarLot\ucPerformanceSummary.cs:line 22
at Baychev.CarLot.ucCanvas..ctor() in C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\CarLot\CarLot\ucCanvas.cs:line 37

Jan 9, 2009 at 8:27 AM
Edited Jan 9, 2009 at 8:37 AM
I haven't encountered that error before but it might be related to these threads..
http://www.codeplex.com/entlib/Thread/View.aspx?ThreadId=15388
http://www.codeplex.com/entlib/Thread/View.aspx?ThreadId=31770


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com
Dec 30, 2009 at 11:44 AM

Hi,

I got the same "The requested database xxx is not defined in configuration." Exception. I found a solution:

My initial settings:

2 projects:

- DataLayer dll

- Asp.net web app

When I called DatabaseFactory.CreateDatabase(connection string) I got the exception. My connection string was defined in a app.config file in the dll project as well as in the web app. I dived a bit deeper into the exception and found out, that it was complaining, that the provided connection string was not defined in the "ConnectionSettings.config". So I went create it. The error stills happened. Then I switched to the parameterless constructor of DatabaseFactory.CreateDatabase. The Exception I got was the same, but it turned out, that the inner Exception was now complaining about a missing provider name in the config file(s by now). I filled the provider name in the connection string tags and everything works fine now, except, that I still can't call the Factory method with a provided connectiong string. I can only use the parameterless constructor.

I hope that helps and I may get an answer why I can't call the constructor with a parameter. Why do I have to define a ConnectionSettings.config anyway?

Cheers, Steve