Ok, fifth time I’ve had to Google this (I keep forgetting the exact steps), and unfortunately not enough people have actually written about this error message for the first 2 to 3 pages in the Google search to be of any use. So let me make this one short and sweet.
You get the following error dialog
The Web project ‘YourProjectNameHere’ requires SQL Server Express, which is not installed on this computer. The recommended database engine for Visual Studio 2012 is SQL Server LocalDB Express.
To upgrade the project database to use SQL Server LocalDB Express, double click the database file and follow the instructions. Note: After this upgrade, the project database cant be modified using earlier versions of Visual Studio. To continue using SQL Server Express for this project, install it from the Microsoft Download Center.
Ok, this sure seems like it is a straight forward thing to fix, but it isn’t (doh). So why isn’t it an easy thing to fix? because with EF and Code First and Design First more and more people are pushing up examples that don’t actually have a database in them. They depend on EF to JIT build the database for the project (and for you) the first time you run their sample.
That of course means you can’t double click on the project database as instructed by the helpful Microsoft dialog, because there IS no project database to double click on. But wait a sec, if there is no project database how is Visual Studio 2012 determining that you aren’t using the latest greatest from Microsoft. Well because despite what the dialog says, VS 2012 is actually NOT looking at the database, it is looking in the project’s active .config file and the connection strings therein.
So for the example of the project above in the web.config here is what comes from the author for the Connection strings entries
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
So the problem here is the section that says “data source=.\SQLEXPRESS”. VS2012 is reading that in the .config file and warning you. Now if there was a database file in the project you could double click it and a wizard would run that would make the necessary changes for you. BUT if the project author left out the database, then you have a chicken / egg problem, you can’t create the database to upgrade it until you have already upgraded the database.
So how do you get around this problem? Easy, just need to make a quick change in the .config file and you are ready to rock
What we need to do is change the .\SQLEXPRESS to indicate instead the LocalDB engine and then EF Code First / Model First will work just fine and your database will be created without requiring you to install SQLExpress.
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|DatabaseName.mdf;User Instance=true"
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\DatabaseName.mdf;Integrated Security=True"
And you are done.