No connection string named 'MyEntities' could be found in the application config file

asp.net-mvc-4 c# entity-framework

Question

I am using entity framework and ASP.NET MVC 4 to build an application

My solution is split into two projects;

  • A class library that includes my data model (.edmx) file and a few custom interfaces
  • The 'container' MVC project that references the class library above

My problem is that when I attempt to use the 'MyEntites' DbContext I get the the following error:

No connection string named 'MyEntities' could be found in the application config file.

I guess the problem has something to do with the fact that connection string lies within the app.config of the class library rather than the MVC project.

Does anyone have any suggestions?

1
243
8/22/2016 6:59:42 PM

Accepted Answer

Try copying the connections string to the .config file in the MVC project.

305
9/27/2012 1:25:05 PM

Popular Answer

You are right, this happens because the class library (where the .edmx file) is not your startup / main project.

You'll need to copy the connection string to the main project config file.

Incase your startup / main project does not have a config file (like it was in my Console Application case) just add one (Startup project - Add New Item -> Application Configuration File).

More relevant information can be found here: MetadataException: Unable to load the specified metadata resource



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow