实体框架使用了错误的连接提供 [英] Entity Framework using the wrong connection provider

查看:491
本文介绍了实体框架使用了错误的连接提供的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用实体框架5(代码优先)为ASP.NET Web窗体应用程序,我以前一直在使用MySQL连接运行的基本实现,我也有过成功使用SQL桌面应用程序的工作Server精简4。



我遇到的问题是,与EF5我收到错误




指定的存储提供不能在配置中找到,或
为无效。




这是很少的帮助。



升级到EF6-RC1给我的



比较有用的误差

有固定名称MySql.Data.MySqlClient'ADO.NET提供者是
无论是在机器或应用程序配置文件没有注册,或
无法加载。详情请参阅内部异常。




至少我现在知道的问题是什么。



我的问题是,我已删除从项目的MySQL的所有痕迹,没有任何理由为什么项目应试图加载MySQL的提供商。



<预类=郎咸平的XML prettyprint-覆盖> <&的EntityFramework GT;
< defaultConnectionFactory TYPE =System.Data.Entity.Infrastructure.SqlCeConnectionFactory,的EntityFramework>
<&参数GT;
<参数值=System.Data.SqlServerCe.4.0/>
< /参数>
< / defaultConnectionFactory>
<供应商>
<供应商invariantName =System.Data.SqlClient的TYPE =System.Data.Entity.SqlServer.SqlProviderServices,EntityFramework.SqlServer/>
<供应商invariantName =System.Data.SqlServerCe.4.0TYPE =System.Data.Entity.SqlServerCompact.SqlCeProviderServices,EntityFramework.SqlServerCompact/>
< /供应商>





<预类=郎咸平的XML prettyprint -override> <&是connectionStrings GT;
<添加名称=im_customerdb的connectionString =数据源= | DataDirectory目录| \CustomerData.sdf的providerName =System.Data.SqlServerCe.4.0/>
< /&是connectionStrings GT;



这是从我的web.config文件的摘录,请让我知道,如果有任何其他的相关章节可能在解决点。



我已经做了通过单词的MySQL解决方案的每个文件的文本搜索和有到MySQL的引用。我已经检查一个干净的版本的项目出源代码控制,以确保净化工程建设文件时,我没有错过一个文件。



谁能提供任何线索,我应该看看,以确定为什么EF是坚持加载MySQL的提供商?



问候,
安东尼



*的编辑:* 的我想补充的异常被抛出的第一次数据库上下文被访问时,从堆栈跟踪正在初始化数据库时异常被抛出。我也发现了一些非常奇特的;被正确创建的数据库文件,这似乎只是EF然后拒绝使用它,并试图使用MySQL。


解决方案

问题解答是旧的,但可能这将是对别人有帮助的。



我已经得到了从甲骨文到MS SQL Server的过渡同样的问题。
最后,似乎代码迁移是问题的根源。
你不能让他们因为是切换到另一个数据库供应商后。
所以,你必须重新生成新的数据库提供商迁移。


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.

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.

which is very little help.

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

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.

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>

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.

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.

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

Regards, Anthony

*Edit: * 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.

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.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆