Sunday 27 September 2015

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

I am using entity framework and ASP.NET MVC 5 and WEB API 2 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.




Answer:


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).






1 comment: