Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

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

I have a one entity framework object and when I add it to my project, the connectionstring is added to app.config in the connectionstring section, but when I want to create new entitycontext and use this connectionstring, this error appears

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...