简体   繁体   中英

database file not showing in app_data in asp.net mvc4 tutorial using visual studios 2010

I'm doing this tutorial on ASP.NET: http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/intro-to-aspnet-mvc-4 and I reached a stage in which I need to work with a database.

Since I'm using Windows XP, LocalDB is not an option, so I configured SQL Server Express instead.

The app is working, but I can't seem to see the MovieDBContext.mdf file in the App_Data folder. I tried refreshing, building, running, nothing helps.

The only thing in that folder is ASPNETDB.mdf . Does this file contain what I'm looking for?

I opened it and it showed a bunch of tables related to users of the app.

My problem comes when it's time to add new fields to the movie class and coordinate it with the database, meaning I have to turn on migration.

Here are the instructions for migration: http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/adding-a-new-field-to-the-movie-model-and-table

Sadly I cannot delete the database files according to this tutorial since I don't have access to the files.

Is there a way to see the .mdf files?

my connection string is:

<add name="MovieDBContext"
     connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=Drivers;AttachDbFilename=|DataDirectory|\Movies.mdf;Integrated Security=True;User Instance=True"
     providerName="System.Data.SqlClient"
/>

In the order they come in your question

The only thing in that folder is ASPNETDB.mdf. Does this file contain what I'm looking for?

Probably yes, it actually depends on the name you gave to the file when it was created.

Your Connection String

Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Movies.mdf;

It looks for a file named Movies.mdf in the App_Data folder whereas your file is names ASPNETDB.mdf, either rename the file to Movies.mdf or change the connection string

Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\ASPNETDB.MDF;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM