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

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

问题描述

我有一个单一实体框架对象,当我将它添加到我的项目时,connectionstring被添加到 connectionstring 部分的 app.config 中,但是当我想创建新的 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天全站免登陆