Aditya
Aditya

Reputation: 1135

.mdf file missing under the App_Data folder in ASP.NET MVC

I was following the tutorial on creating the Code First Entity Framework model on Asp.NET MVC Application from this tutorial.

As I proceeded, a file with the .mdf extension should have been generated under the App_Data folder in my project (in the solution explorer section). Currently this folder is empty.

I have tried building the project and cleaning it. Moreover I have enabled Show All Files option in the folder. I even did a refresh. The Entity Framework works just fine and is able to connect and retrieve from the database. However the App_Data folder is empty.

Here is are my connection strings:

<connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-UsingEntityFramework-20161002112829.mdf;Initial Catalog=aspnet-UsingEntityFramework-20161002112829;Integrated Security=True"
      providerName="System.Data.SqlClient" />
    <add name="MovieDBContext" connectionString="Data Source=tcp:xxxxxxxxxx.net;Initial Catalog=xxxxx;User ID=xxxxx;Password=xxxxxx;" providerName="System.Data.SqlClient"/>
</connectionStrings>

Upvotes: 0

Views: 2431

Answers (1)

Haitham Shaddad
Haitham Shaddad

Reputation: 4456

Check your web.config and notice the connectionString and see the data source, maybe it is creating it under your SQL Server not inside the App_Data

The MDF File will be created when the database is created, and since this is a code first, the database will not be created unless you run the application and start connecting to the database, EF will create the database if it doesn't exist and will compare the schema to the schema in the Migrations folder and it will update the database if it is not up to date.

You can also open Nu Get Package Manager and run the command Update-Database to create and update the database.

Upvotes: 3

Related Questions