Can’t see the .mdf file in the App_data folder? #mvc #aspnet

For those who’re following the ASP.NET Movies tutorial from Microsoft and you get to the stage where you are supposed to look at the Movies.mdf data file, you may encounter some problems. There are quite a few, and these issues aren’t unique to the movies sample and can happen to anyone trying to create projects in this way. Here are a list of problems and solutions.

Problem: The database ‘…MVCMOVIE\MVCMOVIE\APP_DATA\MOVIES.MDF’ cannot be opened because it is version 706. This server supports version 655 and earlier. A downgrade path is not supported.

Solution: [It’s likely you’re running Visual Studio Web Developer or VS2010]

  1.  You need to install the SQL Server Data Tools and LocalDB.
  2. Verify the MovieDBContext connection string specified on the previous page of the tutorial.

Problem : “InvalidOperation Exception was unhandled by user code” The supplied SqlConnection does not specify an initial catalog.

Solution: [It’s likely you’re running Visual Studio Web Developer or VS2010]

  1. You need to install the SQL Server Data Tools and LocalDB.
  2. Verify the MovieDBContext connection string specified on the previous page of the tutorial.

Or

  1. You might get away with just adding “Initial Catalog=Movies;” into the connection string.

Problem: The App_Data folder in the solution explorer didn’t contain the .mdf file

Solution:

  1. In the Solution Explorer, click ‘show all files’.
  2. Then click the refresh button.
  3. Then expand the App_Data folder

Problem: The App_Data folder still doesn’t show anything.

Solution:

  1. F5 (Debug) the solution.
  2. Navigate to <location>/Movies in IE- this step populates the database. You could also try using update-database in nuget package manager console.
  3. Go back to visual studio and refresh the App_Data folder.

– This solution applies to other projects, if your .mdf isn’t there or the tables aren’t there, just try navigating to the main DbSet controller class first. This is because the migrations to code first changes are lazily applied. You can write some code in your startup that ensures all pending migrations are added to the database before any other code is run, which is generally handy anyway. I’ll be covering this in another blog post soon.

Advertisements

2 thoughts on “Can’t see the .mdf file in the App_data folder? #mvc #aspnet

  1. On my case it was that the Entity Framework was using by default the SQL Express Connection, I just changed the config file to:

    an it works.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s