I suspect that your issue is coming from the fact that you have more than one project in your solution and the one that contains your entity framework stuff including edmx
files is NOT the solutions's startup project. In this case even if the connection string exists in the EF app.config
project, still CLR cannot find it at runtime. For example, if you have a web site and a EF project in your solution, you need to copy the connection string from the EF project's app.config
to your website's web.config
. Basically, any connection string data should exist in the config file of the project that the .Net threads initiated from by CLR (i.e. your startup project).
If this is not your case, then just open your edmx
file, right click on its surface, select properties and copy the connection string and paste it into your app.config
Connection String section. This way you can make sure that you are having the correct one in your config.
EDIT:
As you can see here on
Documenation on ObjectContext Constructor, the first parameter is the connectionstring name which is code generated at the time you create your EDM. If, somehow, the name of your connectionstring name happens to be changed, all you need to do is right clicking on your model and selecting "Update Model From Database..." then follow the wizard to update your confing and designer to reflect this change.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…