none
How to execute MyData.edmx.sql RRS feed

  • Question

  • Hi all,

    I asked this question on StackOverflow [here] a couple of days ago, but got no response.  I'll try again here...

    I've created a simple Entity Framework model-first app in VS 2012 by creating an MVC 4 project and adding a single data entity using the designer.

    The first time I right-click the designer surface and select Generate Database From Model it prompts me for the particulars of my database connection.  I tell it to use a local database file in my App_data folder.  When it's done, it has created my (empty) database file, and it presents me with a shiny new MyData.edmx.sql file.

    Ok, so I assume that I need to execute this sql file against my new database file.  But I can't figure out the magic to do so.  When I right-click the sql file and select Execute, it tells me that I'm using a server type of Database Engine, and it asks me for a Server Name.  The only available option seems to be MyPC\SQLEXPRESS.  But when I select that and click on the Connect button, it complains that the the [MyData] database doesn't exist (because I've  told it to use SQL Express and not LocalDb with my database file).

    HELP.  How do I wire up VS to my new database file?

    Bob

    Friday, September 14, 2012 8:31 PM

Answers

All replies

  • Hi Bob.at.SBS,

    Welcome to MSDN Forum.

    Using local database file in Entity Framework, you need to attach the database file to your SQL Server existing instance. Please refer to the steps below.

    1. Attach your database file to an existing SQL Server instance.

    2. Execute the SQL Script to generate the tables in VS.

    3. Detach the database file from the SQL Server instance.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Monday, September 17, 2012 2:36 AM
    Moderator
  • Thanks Allen!

    >  Attach your database file to an existing SQL Server instance.

    How do I do this?  Can I do this using VS 2012, or must I download and install some other bits?  I tried to find the appropriate SQL Server Management Studio bits in Microsoft Downloads, but there are a zillion different flavors available and it's not obvious which download I need to work with whatever version of SQL Server I get out-of-the-box with VS 2012 Ultimate.

    Bob

    Monday, September 17, 2012 2:39 PM
  • Hi Bob.at.SBS,

    Yes, you need a SQL Server Management Studio, here's a tutorial I think can help you, please refer to it.

    http://www.headcrash.us/blog/2010/11/model-first-entity-framework-with-mdf-database-files-in-app_data/

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Bob.at.SBS Tuesday, September 18, 2012 2:57 PM
    Tuesday, September 18, 2012 2:01 AM
    Moderator