繁体   English   中英

“提供者没有返回带有Entity Framework的ProviderManifestToken字符串”MySQL

[英]“The provider did not return a ProviderManifestToken string” MySQL with Entity Framework

我在VS 2017中建立了一个新项目。我的目的是使用EF CodeFirst方法。 到目前为止,我使用的是Azure SQL数据库,而在这个测试项目中我想使用我的远程MySQL数据库。 我创建了用户并且权限设置恰到好处。 我可以通过MySQL Workbench访问此远程数据库服务器。

我创建了一个新的空白MVC项目,并通过Nuget我安装了MySQL.Data.Entity(版本6.9.10)。

我的Context类:

[DbConfigurationType(typeof(MySqlEFConfiguration))]
public class WebDb : DbContext
{
    public WebDb() : base("WebDb")
    {

    }

    public DbSet<Candidate> Candidates { get; set; }
}

我的web.config包含以下条目:

<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <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.10.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
    </providers>
  </entityFramework>
  <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.10.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
  </system.data>

我的连接字符串是:

<connectionStrings>
    <add name="WebDb" providerName="MySql.Data.MySqlClient" connectionString="server=x.x.x.x;uid=dbuser;pwd=password;database=temp1;" />
</connectionStrings>

我有一个简单的域类

public class Candidate
{
    public int Id { get; set; }
    public string Name { get; set; }
}

当我给出Enable-Migrations -Force命令时,我得到了

检查上下文是否以现有数据库为目标... System.Data.Entity.Core.ProviderIncompatibleException:提供程序未返回ProviderManifestToken字符串。 ---> MySql.Data.MySqlClient.MySqlException:无法连接到任何指定的MySQL主机。 at MySql.Data.MySqlClient.NativeDriver.Open()at MySql.Data.MySqlClient.Driver.Open()at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection() at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()at MySql.Data.MySqlClient.MySqlPool.GetConnection()at MySql.Data.MySqlClient.MySqlConnection.Open()at MySql System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection连接)中的.Data.MySqlClient.MySqlProviderServices.GetDbProviderManifestToken(DbConnection连接)---内部异常堆栈跟踪结束---在System.Data.Entity.Core System.Data.Entity.Utilities.DbConnectionExtensions.GetProviderInfo中的MySql.Data.Entity.MySqlManifestTokenResolver.ResolveManifestToken(DbConnection连接)中的.Common.DbProviderServices.GetProviderManifestToken(DbConnection连接)(DbConnection连接,DbProviderManifest& 在System.Data.Entity.Empity.EreityModel(LazyInternalContext internalContext)上的System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)处于System.Data.Entity.Internal.RetryLazy 2.GetValue(TInput input) at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.LazyInternalContext.get_ModelBeingInitialized() at System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(DbContext context, XmlWriter writer) at System.Data.Entity.Utilities.DbContextExtensions.<>c__DisplayClass1.<GetModel>b__0(XmlWriter w) at System.Data.Entity.Utilities.DbContextExtensions.GetModel(Action
2.GetValue(TInput input) at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.LazyInternalContext.get_ModelBeingInitialized() at System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(DbContext context, XmlWriter writer) at System.Data.Entity.Utilities.DbContextExtensions.<>c__DisplayClass1.<GetModel>b__0(XmlWriter w) at System.Data.Entity.Utilities.DbContextExtensions.GetModel(Action
2.GetValue(TInput input) at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.LazyInternalContext.get_ModelBeingInitialized() at System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(DbContext context, XmlWriter writer) at System.Data.Entity.Utilities.DbContextExtensions.<>c__DisplayClass1.<GetModel>b__0(XmlWriter w) at System.Data.Entity.Utilities.DbContextExtensions.GetModel(Action
1 writeXml),System.Data.Entity.Migrations.DbMigrator中的System.Data.Entity.Utilities.DbContextExtensions.GetModel(DbContext context)。 System.Data.Entity.Migrations.Design.MigrationScaffolder..ctor上的System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration配置)中的.ctor(DbMigrationsConfiguration配置,DbContext usersContext,DatabaseExistenceState existState,Boolean calledByCreateDatabase)(DbMigrationsConfiguration migrationsConfiguration) )在System.Data.Entity.Migrations.Design.ToolingFacade.BandRunner.Run()的System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.RunCore()处提供者没有重新
转一个ProviderManifestToken字符串。

据我所知,我已经广泛搜索到无济于事。 这里发生了什么事? 我错过了什么?

我最近遇到了和你一样的问题。 一切都在SQL Server中运行良好,但我在转换到MySQL时遇到了很多问题。 对我有用的一些事情是:

    Install-Package MySQL.Data -Version 6.9.9
    Install-Package MySql.Data.Entity -Version 6.9.10

MySQL的新8.0程序包似乎有问题。 当我恢复到旧版本时,它起作用了。

您的app.config应如下所示:

      <dependentAssembly>
        <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.9.9.0" newVersion="6.9.9.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <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.8.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
    </providers>
  </entityFramework>
  <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.10.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
      <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=c5687fc88969c44d" />
    </DbProviderFactories>
  </system.data>
</configuration>

即使在那之后,我发现MySQL中存在一些差异。 例如,您的迁移“索引”语句将不起作用。 您必须编辑迁移文件并自行构建索引。 我刚刚阅读但未遇到的另一件事是MySQL驱动程序不允许多个连接,这可能意味着改变了检索异步集合的方式。 最后,我遇到RowVersion是byte []的问题。 我使用了以下文章中的变体来解决这个问题(希望如此!)。

使用EF Core和MySQL实现行版本的更好方法是什么?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM