在配置中找不到指定的命名连接,不能与EntityClient提供程序一起使用,或无效 [英] The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid

查看:134
本文介绍了在配置中找不到指定的命名连接,不能与EntityClient提供程序一起使用,或无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个实体框架对象,当我将它添加到我的项目中时, connectionstring
被添加到 app.config connectionstring 部分,但是当我想创建新的 entitycontext 并使用这个 connectionstring ,此错误出现

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

推荐答案

我怀疑您的问题来自事实上,您的解决方案中有多个项目,包含您的实体框架的项目(包括 edmx 文件)不是解决方案的启动项目。在这种情况下,即使连接字符串存在于EF app.config 项目中,仍然CLR在运行时无法找到它。例如,如果您的解决方案中有一个网站和一个EF项目,则需要将EF项目的 app.config 中的连接字符串复制到您网站的的web.config 。基本上,任何连接字符串数据都应该存在于CLR(即您的启动项目)从.Net线程启动的项目的配置文件中。
如果这不是你的情况,那么只需打开你的 edmx 文件,右键单击其表面,选择属性并复制连接字符串并将其粘贴到 app.config 连接字符串部分。这样你就可以确保你的配置正确。




编辑:


您可以在这里看到
在ObjectContext构造函数上的文档 ,第一个参数是连接字符串名称,它是创建EDM时生成的代码。如果不知何故,您的连接字符串名称的名称恰好被更改,您需要做的只是右键单击您的模型,然后选择更新模型从数据库...,然后按照向导进行更新你的配偶和设计师来反映这种变化。

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.


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.

这篇关于在配置中找不到指定的命名连接,不能与EntityClient提供程序一起使用,或无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆