views:

775

answers:

3
<connectionStrings>
      <add name ="MyDB" connectionString ="Data Source=.\SQLEXPRESS" providerName="System.Data.SqlClient"/>
    </connectionStrings>

I've wired the above however I keep getting the following:

System.Configuration.ConfigurationErrorsException: The requested database MyDb is not defined in configuration.

Is there something wrong with the wiring or is the problem located within my code?

DatabaseFactory.CreateDatabase(DB_NAME)

Problem was solved I put the connection in the service config file, however all posts were helpful

+3  A: 

First, you do not have an Initial Catalog, User ID or Password in your connection string. This means the connection string cannot be used to connect to an existing database and won't work in any direct wireup of controls.

Second, I'd need to see your method of getting the connection string since this is what actually led to the error. If fixing the first problem doesn't fix the issue, post the code you use to pull out the connection string for the next step.

Mark Brittingham
it is intentional I dont have inital catalog or credentials at this stage
CodeMonkey
+1 for a great analysis of the problem. I agree completely.
Cerebrus
+1  A: 

check your all web.config content and make sure like this:

<configuration> 
  <connectionStrings> 
    <add name="SQLite" connectionString="Data Source=0" 
      providerName="System.Data.SQLite" /> 
  </connectionStrings> 
</configuration>
cjjer
+2  A: 

For future reference - this website may help, I use it as kind of a cheat sheet.

Pawel Krakowiak
I find it strange that *this* answer should be the accepted one, since it didn't appear from the question or your comments that you have a problem constructing the connection string.
Cerebrus
Cerebrus - me too but this is a *really* good link to I gave it an upvote.
Mark Brittingham
Actually I gave this answer after I first looked at Mark's answer, then looked closer at the OP's connection string and I thought I'd share one of the most useful websites I know. :)
Pawel Krakowiak