My first working with MVC3 and Entity Framework Code First was quite time consuming.I made a model, two controllers and the views generated automatically.I build it and it was successful.But when i press F5, I got the following error:
Server Error in ‘/’ Application.
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 – Error Locating Server/Instance Specified)
I was using SQLServer 2005(Not SQLExpress ) but that was not the problem i configured the connection string like the following:
If you look at the above image you will find that my DBContext name is “MyFirstMvcAppContext” and my connectionstring name was “ApplicationServices”. Here was the problem!!
For Entity Framework Code First connectionstring name should match the name of the DB Context . when i used connectionstring name “MyFirstMvcAppContext” instead of “ApplicationServices”, the site run successfully.