Entity Framework 4 "Generate Database from Model" to SQLEXPRESS mdf results in "Could not locate ent

Posted by InfinitiesLoop on Stack Overflow See other posts from Stack Overflow or by InfinitiesLoop
Published on 2010-06-15T19:39:31Z Indexed on 2010/06/15 19:42 UTC
Read the original article Hit count: 1049

I'm using Visual Studio 2010 RTM. I want to do model-first, so I started a new MVC app and added a new blank edmx. Created a few entities. No problem. Then I "Generate Database from Model", and allow the dialog to create a new database for me, which it does successfully as 'mydatabase.mdf' in the app's App_Data directory.

Then I open the generated sql file (in Visual Studio). To run it of course I have to give it a connection. I am not sure if it's right, but I used '.\SQLEXPRESS' and Windows authentication. No idea how I'd tell it where the MDF is.

Then the problem -- upon executing it, I get:

Msg 911, Level 16, State 1, Line 1 Could not locate entry in sysdatabases for database 'mydatabase'. No entry found with that name. Make sure that the name is entered correctly.

And indeed there were no tables created in the MDF.

So... what am I doing wrong, or am I off my rocker expecting this to work? :)

© Stack Overflow or respective owner

Related posts about database

Related posts about entity-framework