Newbie: How to execute MyData.edmx.sql

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 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?



I encountered a similar issue in trying to execute the edmx.sql under VS 2013, EF6. There is no mention of this solution anywhere else, so I'll add it here for anyone else who might encounter the error: "Database mynewdatabase does not exist". Below is my solution:

  1. Follow the steps to compete the Generate Database from Model.
  2. Open the file *.edmx.sql (it should have opened automatically). Right click anywhere inside the text editor, and select Execute.
  3. If this is your first time connecting to this db, a login prompt will popup. If using LocalDB, enter server exactly as "(localdb)\v11.0" and use Windows Authentication.

Now the issue. If you get an error: "Database mynewdatabase does not exist", here is the fix: Near the top of *.edmx.sql is a line like so:

USE [mynewdatabase];

You must modify this to include the full path of your database filename e.g. so:

USE [D:\Projects\MyNewProject\MyNewProject\App_Data\mynewdatabase.mdf];

Now repeat step 2 and you should get the message that the database was created successfully.

Note1: The .mdf extension is required!

Note2: You must perform this manual edit again every time you Generate Database from Model as that process overwrites the edmx.sql.

Need Your Help

DrawerLayout - ClassNotFoundException while compiling with Android Studio and Gradle

android gradle android-studio android-support-library drawerlayout

I was trying to create a sample app using the new DrawerLayout with the Android Studio and Gradle. I am referring the official google document mentioned here. But whenever I launch the app, it exit...

Unable to put one canvas under another

javascript html css canvas

I want to put a canvas under another. I am pretty new at javascript so i apologize in advance if the following code looks a bit messy. I want to make the canvas called "myCanvas" appear behind

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.