MVC4 error- Unable to complete operation. The supplied SqlConnection does not specify an initial catalog

I was trying to do my hands dirty today with MVC4. I was following MvcMovieStore example. Following everything correctly till “Accessing Your Model’s Data from a Controller”, i was stuck with this error.

Struggling to this i found that by default it uses database with the same name as your context but once you specify custom named connection string you must provide the name of used database either by Initial Catalog or Database parameter.

Final connection string was as under-

<add name="MovieDBContext" connectionString="Data Source=.\SQLEXPRESS;
AttachDbFilename=|DataDirectory|Movies.mdf;Initial Catalog=Movies;
Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
This entry was posted in ASP.NET, Entity Framework, Knowledge Sharing, MVC, Troubleshooting. Bookmark the permalink.

Comments are closed.