实体框架使用了错误的连接提供者

Entity Framework using the wrong connection provider(实体框架使用了错误的连接提供者)
本文介绍了实体框架使用了错误的连接提供者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 Entity Framework 5(代码优先)用于 ASP.NET Web 窗体应用程序,我之前使用 MySQL 连接运行了一个基本实现,并且我也成功使用了使用 SQL 的桌面应用程序服务器紧凑型 4.

I am trying to use Entity Framework 5 (code-first) for an ASP.NET Web Forms application, I have previously had a basic implementation running using the MySQL connection and I have also had success working with a desktop application using SQL Server Compact 4.

我遇到的问题是使用 EF5 时出现错误

The problem I am having is that with EF5 I am getting the error

在配置中找不到指定的商店提供者,或者无效.

The specified store provider cannot be found in the configuration, or is not valid.

这没什么帮助.

升级到 EF6-rc1 给了我更有用的错误

Upgrading to EF6-rc1 gives me the more useful error of

具有不变名称MySql.Data.MySqlClient"的 ADO.NET 提供程序是未在机器或应用程序配置文件中注册,或无法加载.有关详细信息,请参阅内部异常.

The ADO.NET provider with invariant name 'MySql.Data.MySqlClient' is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details.

至少我现在知道问题"是什么.

At least I now know what the "problem" is.

我的问题是我已经从项目中删除了 MySQL 的所有痕迹,项目没有理由尝试加载 MySQL 提供程序.

The issue I have is that I have removed all trace of MySQL from the project, there is no reason why the project should be trying to load the MySQL provider.

<entityFramework>
  <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
  <parameters>
    <parameter value="System.Data.SqlServerCe.4.0" />
  </parameters>
</defaultConnectionFactory>
<providers>
  <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
  <provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
</providers>

<connectionStrings>
<add name="im_customerdb" connectionString="Data Source=|DataDirectory|CustomerData.sdf" providerName="System.Data.SqlServerCe.4.0" />
</connectionStrings>

这些是我的 web.config 文件的摘录,如果有任何其他相关部分可能指向解决方案,请告诉我.

These are excerpts from my web.config file, please let me know if there are any other relevant sections that might point at the solution.

我已经在解决方案中的每个文件中对 MySQL 一词进行了文本搜索,并且没有对 MySQL 的引用.我已经从源代码控制中检查了项目的干净版本,以确保在清除项目构建文件时没有错过任何文件.

I have done a text search through every file in the solution for the word MySQL and there are no references to MySQL. I have checked a clean version of the project out of source control to be sure that I haven't missed a file when purging the project build files.

任何人都可以提供任何线索来说明我应该在哪里确定为什么 EF 坚持加载 MySQL 提供程序?

Can anyone provide any clues as to where I should look to determine why EF is insisting on loading a MySQL provider?

问候,安东尼

** 只是补充一点,在第一次访问数据库上下文时会引发异常,从堆栈跟踪来看,在初始化数据库时会引发异常.我还注意到一些非常奇怪的东西.数据库文件正在正确创建,似乎 EF 然后拒绝使用它并尝试使用 MySQL.

* * Just to add that the exception is thrown the first time the database context is accessed, from the stack trace the exception is being thrown when the database is being initialised. I've also noticed something very peculiar; the database file is being created correctly, it just seems that EF then refuses to use it and tries to use MySQL.

推荐答案

问题很老,但可能对某人有帮助.

Questions is old, but may be this will be helpful for somebody.

我在从 Oracle 过渡到 MS SQL Server 时遇到了同样的问题.最终,代码迁移似乎是问题的根本原因.在切换到另一个数据库提供程序后,您不能只保留它们.因此,您必须为新的数据库提供程序重新生成迁移.

I've got the same issue with transition from Oracle to MS SQL Server. Eventually, it appeared that code migrations were the root cause of the issue. You cannot just leave them as is after switching to another database provider. So, you must REGENERATE migrations for your new database provider.

这篇关于实体框架使用了错误的连接提供者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)