EntityFramework Connection problem

别来无恙 提交于 2019-12-11 02:29:10

问题


I have a solution in Visual Studio 2008 with 3 projects. One Web Application and 2 class libraries. The entity framework model is in a class library and the start project is the web application.

I used to have this problem:

"The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid."

I fixed it copying the connection string from the App.config of the class library where the entity model is located to the web.config of my web application (start project).

I found that workaround posted here: Problem with connectionstring and entityframework

But my question is: ¿how can i avoid using the connection string from the web.config and use the one from the app.config where the entity model is located?

Thank you very much.


回答1:


I'd suggest to copy the connection string. this is .Net configuration works. Per executable application there is one App.config. In your case the Web.config of your web application that's running.

You could embed the app.config from the EF project into the assembly extract it in your executing assembly read the connection string and use the overloaded constructor... but stay with version 1 :-)




回答2:


It will always use the connection string in the host application. In your case, that is the web.config. Options are to use MSBuild to rewrite the web.config...



来源:https://stackoverflow.com/questions/3865001/entityframework-connection-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!