Attaching to .mdf

Jan 18, 2011 at 10:19 PM

I am following the example and when I get to the point of trying to display the list of genres the application is creating MvcMusicStore.Models.MusicStoreEntites in the SQLExpress Data Directory instead of using the mdf file in the APP_DATA folder.

Jan 18, 2011 at 10:39 PM

Is your database file being added in the correct folder, as shown in the steps at the top of

Jan 18, 2011 at 11:42 PM

Yes, it is in the APP_DATA folder. I just re-added to the folder but it still is attaching to the version of the database in the SQLExpress data directory instead of the one in the folder. Even if I use the version of the project from the zip file it gives me the same result.  Can it be the version of the entity framework I'm using. I'm using CTP5. 

Jan 27, 2011 at 12:16 AM

Can you copy in your connectionStrings section from your web.config? It should look exactly like this:

    <add name="MusicStoreEntities"
         connectionString="data source=.\SQLEXPRESS; 
        Integrated Security=SSPI;
         User Instance=true"
          providerName="System.Data.SqlClient" />
Apr 7, 2011 at 7:02 AM
Edited Apr 7, 2011 at 7:03 AM

Im getting this error message when I try to open the mdf file within vs2010:

The database '*.MDF' cannot be opened because it is version 655. This server supports version 612 and earlier. A downgrade path is not supported.

Im using vs2010 and got sql express installed, what may have been the issue?

Apr 7, 2011 at 7:51 AM

If you have SQL Server 2005 installed, it may be the default instance. Can you check if this helps you?

May 21, 2011 at 10:46 PM

I'm using a Sql Server 2008 Database on a remote server(or local) and i couldn't connect to my database.

This is my connection string : <add name="LocalConnectionString" connectionString="Data Source=;Initial Catalog=MyDatabase;Persist Security Info=True;User ID=sa;Password=******" providerName="System.Data.SqlClient"/>

Can anyone give me the correct connection string to use.


May 22, 2011 at 9:14 PM

HaythemTlili - I recommend that you test out your connection string using a UDL file. Here's a good blog post with instructions on how to do that:

May 23, 2011 at 12:06 PM

Thank you Jon, the connection string worked for me and i have one more question.

I'm using Entity Framework 4.1 (Database First) and everything is going great but the Edit action does not work for me.

Here's the code :


public ActionResult Edit(Category category)
    if (ModelState.IsValid)
        db.Entry(category).State = EntityState.Modified;

        return RedirectToAction("Index");

    return View(category);

And on the SaveChanges Method i got this : 

DbUpdateConcurrencyException was unhandled by user code.
Store update, insert, or delete statement affected an unexpected number of rows ({0}). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries.

And when i hit a break point i found the the CategoryID is 0.

Is there any solution ?

Jun 4, 2011 at 8:57 AM

I am experiencing exactly the same issue, been trying all work arounds but none successful so far, will post asap

Jun 4, 2011 at 11:12 PM
Edited Jun 4, 2011 at 11:39 PM

alrighty after going into a couple of debugs I did findthat the record id reverts to 0 (zero) where for example it needed to be 1 (or the same as the record id in the db), look at this solution,maybe it will help you, updated the forum with a fix that worked for me

Nov 11, 2011 at 11:38 AM

Hi, I was having various problems trying to run the MvcMusicStore v3.0 against SQL Express and I worked out 2 possible solutions.

I got it running out of AppData as a .mdf file, or hosted on my .\SQLExpress instance using the SampleData.cs. I have full notes on my blog @

Hope it helps, Note: I haven't tested up to the edit stage so I may update the article if I hit further problems. Cheers

Mar 27, 2012 at 9:08 AM
Edited Mar 27, 2012 at 9:13 AM
This DbUpdateConcurrencyException is due to this line in the Album.cs class : [Bind(Exclude = "AlbumId" )]
AlbumId is not mapped to the parameter of this function :
        public ActionResult Edit(Album album)

either you remove the line  [Bind(Exclude = "AlbumId")] of the Album.cs class either you add in the method :

        public ActionResult Edit(Album album)
            if (ModelState.IsValid)
                album.AlbumId = int.Parse(Request.Form["AlbumId"]);

I don't understand though why they added this line on top of the Album.cs class.