DB is not defined in configuration

Apr 18, 2009 at 4:19 PM
Hi to all, 
I have a problem with my DAAB. I configured it in ent lib configuration tool, i checked the Connection string in app.config, and everything seems fine. But, when i try to start the application, the error occurs and it says :
"The requested database is not defined in configuration"
I don't have any other configuration files rather than app.config, would that be a problem, and I don't know how to create dataConfiguration.config if it is necessary... Could anyone help me please ? I'm sooo stucked with this!!!
Thanks in advance!!

Luka
Apr 20, 2009 at 2:04 AM
It is not necessary to create a separate dataConfiguration.config.  Did you add the connection strings under the Data Access Application block in your config?  Please post your <dataConfiguration> section and your call to DatabaseFactory.CreateDatabase here.


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com
Apr 20, 2009 at 12:00 PM
The dataConfiguration section is

<configSections>
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </configSections>
  <dataConfiguration defaultDatabase="BazArtikalaConnectionString" />

 <connectionStrings>
    <add name="BazArtikalaConnectionString" connectionString="Data Source=.\sqlexpress;Initial Catalog=BazArtikala;Integrated Security=True"
      providerName="System.Data.SqlClient" />
</connectionStrings>

I thought it was conifugured like it should have been, but i'm not sure... And here is call to Database Factory


 Database db = DatabaseFactory.CreateDatabase();
 dbc = db.GetStoredProcCommand("getArtikal");
.
.
.

But even when I call like this

Database db = DatabaseFactory.CreateDatabase("BazArtikala");

which is the name of my database, it can't find it.
I really don't know what else to do!!!
Thanks

Luka


Apr 20, 2009 at 12:42 PM
I'm also getting the error:
"Object reference not set to an instance of the object"
when i try to assign DataSet containing data from the database to something, maybe it's just because i can't connect to DB but i'm not sure of anything anymore!!

Luka
Apr 20, 2009 at 9:42 PM

I'm not sure why the default isn't working, but when getting by name, you need to give the name of the connection string, not your actual database. Can you try:

Database db = DatabaseFactory.CreateDatabase("BazArtikalaConnectionString");

and see what happens?

-Chris
Apr 21, 2009 at 2:35 PM
Yes, I know, i just tried it again, like you said, but same thing happens!!!
Thanks anyway

Luka
Apr 22, 2009 at 2:54 AM
Are you getting the same error? (The requested database is not defined in configuration).  How about the null reference exception?  From what line of code are you encountering it?  Is that code part of an executable project or a class library?


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com
Apr 22, 2009 at 1:17 PM
In this line of code:
Database db = DatabaseFactory.CreateDatabase("BazArtikalaConnectionString");

it's the class library, not executable!!
Apr 22, 2009 at 1:27 PM
Where is your configuration then from which your dataconfiguration is defined?  It should be in the executable project which references your class library project.


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com
Apr 22, 2009 at 2:11 PM
I don't know, i just have the Connection String defined in app.config of this class library!!!
Apr 23, 2009 at 6:35 AM
I think you should be defining the connection string to the app.config of the application hosting the class library. Example, if a Console Application is using your class library, you should define the connection string to the app.config of the console application.

Valiant Dudan
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com
Apr 23, 2009 at 11:53 AM
Yes, i thought it so also, and I tried and it finnally works, thank you so much, it was a simple mistake but I'm glad it works now !!!
Luka