首页 > 解决方案 > 具有不变名称“MySql.Data.MySqlClient”的 ADO.NET 提供程序不会注册 MySql.Data.Entity.EF6.dll

问题描述

过去 2 天我一直在挖掘,但我的应用程序连接到我的数据库时仍然存在问题。该服务已安装并启动,但在尝试执行任务时失败。在这里挖掘这篇文章后,我尝试注册它正在使用的 dll,但我收到一条奇怪的错误消息。如果您需要任何信息,请告诉我。一个正确方向的点会很有帮助。谢谢。

日志:

2020-06-02 11:07:42 [JMSQuartzScheduler_Worker-3] NT AUTHORITY\SYSTEM
ERROR  : An error occurred while executing HistoryCleanupJob.
Exception: 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. StackTrace:
    at System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderFactoryResolver.<GetService>b__0(ArgumentExceptione, String n)
    at System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderFactoryResolver.GetService(Type type, Object key, Func`3 handleFailedLookup)
    at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
    at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
    at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
    at System.Data.Entity.Infrastructure.DependencyResolution.RootDependencyResolver.GetService(Typetype, Object key)
    at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
    at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
    at System.Data.Entity.Infrastructure.DependencyResolution.CompositeResolver`2.GetService(Type type, Object key)
    at System.Data.Entity.Infrastructure.DependencyResolution.DbDependencyResolverExtensions.GetService[T](IDbDependencyResolver resolver, Object key)
    at System.Data.Entity.Core.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString)
    at System.Data.Entity.Internal.LazyInternalConnection.InitializeFromConnectionStringSetting(ConnectionStringSettings appConfigConnection)
    at System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig(String name, AppConfig config)
    at System.Data.Entity.Internal.LazyInternalConnection.Initialize()
    at System.Data.Entity.Internal.LazyInternalConnection.CreateObjectContextFromConnectionModel() at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
    at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
    at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
    at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
    at System.Data.Entity.Internal.Linq.InternalSet`1.ActOnSet(Action action, EntityState newState, Object entity, String methodName)
    at System.Data.Entity.Internal.Linq.InternalSet`1.Attach(Object entity)  
    at System.Data.Entity.DbSet`1.Attach(TEntity entity)
    at JMS.Data.Repositories.GenericRepository`1.Update(TEntity entityToUpdate)
    at JMS.Jobs.DBStatusReportingJob.JobDidExecute(IJobExecutionContext context, String errorMessage)
    at JMS.Jobs.DBStatusReportingJob.Execute(IJobExecutionContext context)   
    at JMS.Jobs.LoggingJob.Execute(IJobExecutionContext context)
Exception: Unable to find the requested .Net Framework Data Provider. 
It may not be installed.

在我的配置中,我有这个:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=aaaaac56193bbbbb" />
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>
  <connectionStrings>
    <add name="MySqlConnectionString" connectionString="server=127.0.0.1;User Id=root;password=xxxxxxx;database=scenter;default command timeout=600" providerName="MySql.Data.MySqlClient" />
    <add name="EDocContext" connectionString="metadata=res://*/Data.Models.EDocModel.csdl|res://*/Data.Models.EDocModel.ssdl|res://*/Data.Models.EDocModel.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=127.0.0.1;user id=root;password=xxxxxxx;database=scenter&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="MySql.Data" publicKeyToken="aaaaafc8896bbbbb" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.9.9.0" newVersion="6.9.9.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Autofac" publicKeyToken="aaaaaaf14b0bbbbb" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

  <system.web>
    <membership defaultProvider="ClientAuthenticationMembershipProvider">
      <providers>
        <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=aaaaa856ad3bbbbb" serviceUri="" />
      </providers>
    </membership>
    <roleManager defaultProvider="ClientRoleProvider" enabled="true">
      <providers>
        <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
      </providers>
    </roleManager>
  </system.web>
  <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=6.9.9.0, Culture=neutral, PublicKeyToken=aaaaafc8896bbbbb" />
    </DbProviderFactories>
  </system.data>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.9.0, Culture=neutral, PublicKeyToken=aaaaafc8896bbbbb"></provider>
    </providers>
  </entityFramework>
</configuration>

我做了什么:

  1. 确保我已安装并运行 mysql-connector-net-6.9.9
  2. 确保我可以连接到数据库并且没有任何问题
  3. 卸载并重新安装mysql
  4. 从配置中删除了版本号
  5. 尝试运行 regsvr32 MySql.Data.Entity.EF6.dll -> 这会导致以下错误:

在此处输入图像描述

标签: c#mysql.netregsvr32mysql.data

解决方案


推荐阅读