Search code examples
sql-serverdatabaseentity-frameworkentity-framework-4

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


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'.


Solution

  • 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;