c# - Entity Framework 中的 System.Data.ProviderIncompatibleException

标签 c# asp.net-mvc entity-framework asp.net-mvc-4 controller

我的连接字符串中是否缺少任何内容以致出现此错误:

An exception of type 'System.Data.ProviderIncompatibleException' occurred in EntityFramework.dll but was not handled in user code Additional information: An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct.

这是我在 web.config 中的连接字符串:

<connectionStrings>
    <add name="OnlineStoreEntities" connectionString="Data Source=SERVERNAME\SQLEXPRESS;Initial Catalog=MVCOnlineShop;Integrated Security=True" providerName="System.Data.SqlClient" />
  <add name="MVCOnlineShop" connectionString="metadata=res://*/Models.ShopModel.csdl|res://*/Models.ShopModel.ssdl|res://*/Models.ShopModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=AHMADZAKARIA-PC;initial catalog=MVCOnlineShop;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>

最佳答案

检查 *.config 文件中的连接字符串,很可能您缺少 providerName="System.Data.SqlClient"。参见 Entity Framework Config File Settings了解更多信息

关于c# - Entity Framework 中的 System.Data.ProviderIncompatibleException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44945937/

相关文章:

asp.net-mvc - 带 URL 重写的 MVC 图像处理程序

c# - 如何将 EntityCollection<T> 转换为 List<T>

c# - Entity Framework 多个多对多查询

c# - FakeItEasy 配置 fake 以抛出异常并在下一次调用时返回值

c# - 加载程序集无法正常工作

c# - 在代码隐藏中获取控制的值(value)

c# - 正则表达式仅用于数字加上 'h' 字符

asp.net - 如何控制重复的 Ajax 'post' 提交?

c# - Asp.Net Core - 最简单的表单例份验证

c# - 在生产源代码中将 Entity Framework 日志记录设置为调试窗口是否可以?