【问题标题】:No Entity Framework provider found ... with invariant name 'System.Data.SqlClient'找不到实体框架提供程序...具有不变的名称“System.Data.SqlClient”
【发布时间】:2014-06-12 14:06:22
【问题描述】:

这里的帖子似乎都没有解决我的错误的这个特定版本,但我可能只是遗漏了一些东西......

情况:

MVC 网站使用 WCF 服务。数据保存在 WCF 服务中。两者都在运行

    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />

两者都有连接字符串:

    <add name="SiteTrackerEntities" connectionString="metadata=res://*/VisitorInformation.csdl|res://*/VisitorInformation.ssdl|res://*/VisitorInformation.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=BADLANDS\;initial catalog=SiteTracker;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

网站一直运行,直到我真正尝试使用(第二行错误)保存到 WCF 服务中的数据库...

SiteTrackerEntities db = new SiteTrackerEntities();
db.Entry(visitorData).State = System.Data.Entity.EntityState.Added; 

然后我得到这个可爱的错误:

VisitorInformation.ssdl(2,2) : error 0152: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
  • 确保两者都使用相同版本的 EF (6.0)。检查。
  • 尝试在连接字符串中输入提供程序名称但已使用providerName="System.Data.EntityClient"
  • 尝试使用 PM 控制台删除和重新安装 EF。检查。
  • 手动删除 Ef 引用并重新读取它们。检查。
  • WCF 服务引用了 Entity.Framework.SqlServer(版本 6.0.0.0)。检查。
  • MVC 应用程序具有到仅在 WCF 服务中使用的数据库的连接字符串(奇怪的是它需要它但没关系)。检查。

我错过了什么?

【问题讨论】:

  • 您是否通过 NuGet 在 WCF 项目上安装了 EF6?
  • 多项目解决方案。在 PM 控制台中运行它会将其添加到两个项目中,修改两个 .config 文件以同步到相同的版本。 Moo 为我指明了正确的方向。

标签: c# .net asp.net-mvc entity-framework wcf


【解决方案1】:

确保您的 Web.config 或 App.config 中有类似于以下内容的内容。

<entityFramework>
   <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
   <providers>
     <provider invariantName="System.Data.SqlClient"         type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
   </providers>
</entityFramework>

【讨论】:

  • 做到了。它已经在应用程序配置中,但不在网络配置中。它不再在那条线上出错,但现在正在喋喋不休地谈论不存在插入功能或一些废话。你得到答案和投票!谢谢
  • 问题:为什么MVC项目需要在web.config中有数据信息,虽然WCF服务是访问数据库的?
  • 这是因为.net默认使用调用应用程序的配置文件。在大多数情况下,它是主要的 web/windows 应用程序。
  • 谢谢。我想我在“模块化编码”范式中的想法有点过于极端了。
猜你喜欢
  • 2014-02-06
  • 2013-08-29
  • 1970-01-01
  • 1970-01-01
  • 2014-03-05
  • 1970-01-01
  • 2013-11-18
  • 1970-01-01
相关资源
最近更新 更多