My Software Notes

Useful things I discover

MVC 4 Beta – Single Page Application Tutorial – Gotcha

with 6 comments

I’m currently trying out the ASP.NET MVC 4 Beta and I thought I’d give the Single Page Application tutorial a shot.

I’ve created several single page apps so far and they’re working well and people are using them successfully, but now that I’ve had some experience I look at them and wish I could rewrite them from scratch.  If you look back at code you wrote six months ago and don’t think that you could do it better now then either you are perfect or you have stopped learning and are fast becoming antiquated.

Anyway, I want to start using frameworks like knockout.js and backbone.js, and the SPA (Single Page Application) template that comes with MVC 4 uses knockout.js – great.

So I followed the instructions, hit F5 to run the web site, typed “Tasks” in the address bar and … aaargh!  An exceptions in the view and a really unhelpful error message.  “System.InvalidOperationException was unhandled by user code” and “Failed to get the MetadataWorkspace for the DbContext type ‘MvcSpaApp1.Models.MvcSpaApp1Context’.”  The inner exception was no better: “System.Data.ProviderIncompatibleException” and “The provider did not return a ProviderManifestToken string.”

Luckily I’ve been reading up on Entity Framework Code First, so I knew what the problem was – I didn’t have SQL Server Express running.  So I started up SQL Server Express and … still didn’t work.  But this time it was because I didn’t have rights to SQL Server because I was using a machine someone else set up and they had mucked up the security.  Anyway, when I finally got it all sorted out the site ran without any problems.


Other than those gotchas the tutorial is good.


Written by gsdwriter

March 2, 2012 at 11:29 am

6 Responses

Subscribe to comments with RSS.

  1. You can also set the connection string inside the DbContext class’ constructor.
    Use this.Database.Connection.ConnectionString = “YourConnectionString”;


    March 14, 2012 at 3:18 pm

  2. Can I have this 30 seconds of my life back please?


    March 31, 2012 at 4:56 pm

  3. Thankyou! I had the same problem. Your link at the top took me to the tutorial, which I hadn’t seen, and in the comments I found the solution, which is to change the connection string in global.asax to “Data Source=(localdb)\\v11.0; Integrated Security=True; MultipleActiveResultSets=True”. (note the escaped “\” before v11.0″.


    June 5, 2012 at 2:06 am

    • Oh, and I didn’t have to start SQLExpress. After fixing the connection string it worked automatically.


      June 5, 2012 at 2:08 am

  4. Hey do you know if it is possible to get this tutorial running without sql express, I have sql server 2008??


    November 22, 2012 at 5:40 am

    • You have to modify the connection string or the DbContext derived class. I recently saw a tutorial for MVC4 in which the default project template in VS 2012, sets up SQL Server LocalDB and that works out-of-the-box.


      May 16, 2013 at 12:36 pm

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: