编程技术网

关注微信公众号,定时推送前沿、专业、深度的编程技术资料。

 找回密码
 立即注册

QQ登录

只需一步,快速开始

极客时间

Mysql实体框架异常:Mysql Entity framework exception

TD-wzw mysql 2022-5-11 10:23 7人围观

腾讯云服务器
Mysql实体框架异常的处理方法

  • .Net Framework:4.7.2
  • 已安装MySql服务器:8.0.12
  • MySql连接器/网络:8.0.12
  • 实体框架:6.2.0
  • MySql.Data:8.0.12
  • MySql.Data.EntityFramework:8.0.12

Web.config配置

Web.config configuration

<system.data> <DbProviderFactories> <remove invariant="MySql.Data.MySqlClient" /> <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.EntityFramework, Version=8.0.12.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /> </DbProviderFactories> </system.data> <connectionStrings> <add name="DefaultConnection" connectionString="server=localhost;user=root;database=app;password=root;" providerName="MySql.Data.MySqlClient" /> </connectionStrings> <providers> <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.EntityFramework, Version=8.0.12, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/> </providers> 

在连接到数据库时,出现如下异常:所请求的.Net Framework数据提供程序的实现没有System.Data.Common.DbProviderFactory派生类型的Instance字段.

While connecting to DB, getting exception like below: The requested .Net Framework Data Provider's implementation does not have an Instance field of a System.Data.Common.DbProviderFactory derived type.

问题解答

< DbProviderFactories> 中的配置信息不正确.根据 MySQL Connector/NET文档,它应该是:

The configuration information in <DbProviderFactories> is incorrect. According to the MySQL Connector/NET documentation it should be:

<system.data> <DbProviderFactories> <remove invariant="MySql.Data.MySqlClient" /> <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=8.0.12.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /> </DbProviderFactories> </system.data> 

这篇关于Mysql实体框架异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程技术网(www.editcode.net)!

腾讯云服务器 阿里云服务器
关注微信
^