Shlo
Shlo

Reputation: 1046

sdf file not showing in App_Data (using MVC application)

I followed the "Creating an Entity Framework Data Model for an ASP.NET MVC Application" in ASP.net and changed it to meet my needs. I built the project and run it - everything works fine (I can view details, edit and save). I press "Show all files" and there is nothing under App_Data. I tried to read the related threads here but i couldn't fix it. I will appriciate any Idea!

this is my connection string:

<connectionStrings>
<add name="ApplicationServices"
     connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
     providerName="System.Data.SqlClient" />

Thank you!

Upvotes: 1

Views: 2287

Answers (2)

pzelenovic
pzelenovic

Reputation: 428

To all of those who "tried everything" when it comes to this issue and it still doesn't work, if you can run the app, try saving a record in the database, as the .sdf file will only be created once the first record is created. Then switch off and on again the show all files button and the .sdf file should show up.

Good luck!

Upvotes: 0

devdells
devdells

Reputation: 31

First thing is that your connection string indicates this is a SQLExpress database file. Probably located under the data directory under SQLExpress install location.

Second, I ran a tutorial and chose to use a SQL Compact database. That file (.sdf) I would expect to show up under the App_data folder. It did not. Since the database was generated via 'code first' I suspect this is a bug. All I had to do to fix it (working in the Solution Explorer of VS 2012 RC) was right-click on the App_data folder and choose . And I had to set the .sdf file properties so it would copy to the output file.

I knew I had to do this because my web deploy failed to write the .sdf file to my IIS server. When I republished, the 'Preview' showed me that the .sdf file was going to deployed to /bin/app_data of my web application folder.

If you are using a SQLExpress database, it might require slightly different steps. But your problem is similar and I think we can say this is a bug in the Entity Framework when working within Visual Studio.

Upvotes: 1

Related Questions