views:

118

answers:

2

Hi,

I'm trying to generate my database tables from my Entity Framework model, but I'm getting this error when I execute the generation query:

Database 'Database' does not exist. Make sure that the name is entered correctly.

I'm able to connect to the local server just fine.

My connection string, which was generated by VS when I selected 'Database.mdf':

metadata=res://*/Models.Models.csdl|res://*/Models.Models.ssdl|res://*/Models.Models.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True"

The database definitely exists, but I've noticed that the only databases it's picking up on the server are called master, model, msdb and tempdb.

Can anyone help?

Edit: I've just realised that the SQL connection dialog that comes up when you click "Execute SQL" allows you to connect to a server. But my DB isn't on a server, it's just a user instance database. But that's the only option, so how would I execute against my database? I have the database open in the 'Server Explorer'.

A: 

I can't speak for Entity Framework, but within SQL, "database" is a (very) reserved word. Try calling your database (and it's files) something else, even if just "MyDatabase".

Philip Kelley
Good idea, but sadly, the same thing happens. =(
Matt H
+1  A: 

The connection string is referring to a user instance database is that what you intended? I got the impression possibly not from the question.

If not try changing it to Data Source=ServerName\InstanceName;Initial Catalog=Database;Integrated Security=True;

Martin Smith
You're right, that's wrong. I've just realised that the SQL connection dialog that comes up when you click "Execute SQL" allows you to connect to a server. But my DB isn't on a server, it's just a user instance database.But that's the only option, so how would I execute against my database? I have the database open in the 'Server Explorer'.
Matt H
Do you need it to be a user instance database? If not I'd probably just copy the mdf file and attach it to your SQL Express Instance (in Management Studio) then update the connection string to look at the main SQL Express instance. If you do need it to be a user instance one then I guess you'll need to get to the bottom of it some other way. I haven't worked with user instances I'd probably fire up process monitor and see if it is looking in the wrong place for your mdf file or something http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx
Martin Smith
Doing everything from SQL Management Studio worked. Thanks Martin.
Matt H