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.
这篇关于实体框架使用了错误的连接提供者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:实体框架使用了错误的连接提供者
基础教程推荐
- c# Math.Sqrt 实现 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- SSE 浮点算术是否可重现? 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01