Reputation: 11
I am using the tutorial from the ASP.Net MVC site to upgrade my skills to ASP.Net MVC 3, Entity Framework, SQL CE 4.0 etc. However, I am using Visual Studio 2010 Professional, not Express. On this lesson the SQL CE 4.0 database Movies.sdf is supposed to be created automatically and stored in App_Data. However, the program runs fine, I can create, insert items, stop debugging and restart and the data is still there. However there is no Movies.sdf file in the App_Data folder or any other folder in the project.
I downloaded Visual Studio 2010 Express, ran through the steps again for the tutorial, and the file is created in App_Data this time.
My question is: Where is the |DataDirectory| pointing to in Visual Studio 2010 Professional and why is it different from VS 2010 Express? Is there any way I can check before running a program where |DataDirectory| is set to?
Upvotes: 1
Views: 2443
Reputation: 121
I thought I had a similar issue. Turns out I had made a typo in my connectionstring name.
EF4 code first will only pick up on the connection string if it is named exactly the same as your DBContext class. You'll probably find that it is using the default SQLExpress connection string.
If you want to set the path manually, you can put this in the Application_Start()
protected void Application_Start()
{
AppDomain.CurrentDomain.SetData("DataDirectory", "C:\\pathToMyDatabase\\");
}
You can see the default values for DataDirectory here: SQL Server Compact 'Data Directory' macro in Connection String - more info needed
Upvotes: 1