【问题标题】:How to have multiple projects accessing same Entity Framework project?如何让多个项目访问同一个实体框架项目?
【发布时间】:2011-02-13 01:37:41
【问题描述】:

好的,这个问题已经被问过很多次了。只需用谷歌搜索错误消息:

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

我已经尝试了论坛、帮助网站和博客上的所有建议...没有任何效果!

情况回顾

我将解决方案分成三个不同的项目:一个用于我的 EF4 模型,一个用于 WinForm 和一个 ASP.NET MVC Web 应用程序。我的连接字符串和配置有问题。

是否有使用 VS2010/EF4/.NET Framework 4.0 的更新解决方案?

【问题讨论】:

标签: entity-framework


【解决方案1】:

不确定,但您可能必须将 EF4 项目的 app.config 文件中的实体框架配置部分移动到 WinForm app.config 和 ASP.NET MVC web.config 文件中。

【讨论】:

    【解决方案2】:

    真的,答案是复制上面提到的其他项目的配置文件中的<connectionStrings> 部分。

    <connectionStrings>
        <add name="DataEntities" connectionString="metadata=res://*/DataModel.csdl|res://*/DataModel.ssdl|res://*/DataModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=xxx;Initial Catalog=xxx;User Id=xxx;Password=xxx;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
    </connectionStrings>
    

    所以,这与我之前在许多网站上看到的答案相同。事实上,它从一开始就工作,但我有另一个错误(“配置系统初始化失败”),所以我认为这是 app.config 中连接字符串的错误值。事实上,app.config 是有效的,但只是移动底部的部分就解决了这个问题......奇怪吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-13
      • 2019-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多