My First Experience with MVC3 and Entity Framework Code First

Problem
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:

Solution:
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.

Advertisements

2 thoughts on “My First Experience with MVC3 and Entity Framework Code First

  1. Amazing issues here. I am very satisfied to see your article.
    Thank you so much and I’m having a look forward to touch you. Will you please drop me a mail?

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