简体   繁体   English

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

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

I have set up a new project in VS 2017. My intention is to use EF CodeFirst approach. 我在VS 2017中建立了一个新项目。我的目的是使用EF CodeFirst方法。 So far I used Azure SQL Database, while in this test project I want to use my remote MySQL database. 到目前为止,我使用的是Azure SQL数据库,而在这个测试项目中我想使用我的远程MySQL数据库。 I have created the user and permissions are set just right. 我创建了用户并且权限设置恰到好处。 This remote database server is accessible to me over MySQL Workbench. 我可以通过MySQL Workbench访问此远程数据库服务器。

I have created a new blank MVC project and through Nuget I installed MySQL.Data.Entity (version 6.9.10). 我创建了一个新的空白MVC项目,并通过Nuget我安装了MySQL.Data.Entity(版本6.9.10)。

My Context class: 我的Context类:

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

    }

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

My web.config has these entries: 我的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>

And my connection string is: 我的连接字符串是:

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

I have a simple domain class 我有一个简单的域类

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

When I give Enable-Migrations -Force command, I get 当我给出Enable-Migrations -Force命令时,我得到了

Checking if the context targets an existing database... System.Data.Entity.Core.ProviderIncompatibleException: The provider did not return a ProviderManifestToken string. 检查上下文是否以现有数据库为目标... System.Data.Entity.Core.ProviderIncompatibleException:提供程序未返回ProviderManifestToken字符串。 ---> MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the specified MySQL hosts. ---> 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.Data.MySqlClient.MySqlProviderServices.GetDbProviderManifestToken(DbConnection connection) at System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) --- End of inner exception stack trace --- at System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) at MySql.Data.Entity.MySqlManifestTokenResolver.ResolveManifestToken(DbConnection connection) at System.Data.Entity.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& 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& providerManifest) at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) at 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
在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) at System.Data.Entity.Utilities.DbContextExtensions.GetModel(DbContext context) at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext, DatabaseExistenceState existenceState, Boolean calledByCreateDatabase) at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration) at System.Data.Entity.Migrations.Design.MigrationScaffolder..ctor(DbMigrationsConfiguration migrationsConfiguration) at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.RunCore() at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run() The provider did not re
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()处提供者没有重新
turn a ProviderManifestToken string. 转一个ProviderManifestToken字符串。

I have searched far and wide to the best of my knowledge to no avail. 据我所知,我已经广泛搜索到无济于事。 What's happening here? 这里发生了什么事? What am I missing? 我错过了什么?

I've been having the same problems as you recently. 我最近遇到了和你一样的问题。 Everything worked fine in SQL Server, but I was having lots of problems converting to MySQL. 一切都在SQL Server中运行良好,但我在转换到MySQL时遇到了很多问题。 Some things that worked for me are: 对我有用的一些事情是:

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

The newer 8.0 packages of MySQL appear to have problems. MySQL的新8.0程序包似乎有问题。 When I reverted to an older version, it worked. 当我恢复到旧版本时,它起作用了。

Your app.config should look like: 您的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>

Even after that, there are some discrepancies in MySQL that I'm just finding out. 即使在那之后,我发现MySQL中存在一些差异。 For example, your migration "index" statements will not work. 例如,您的迁移“索引”语句将不起作用。 You'll have to edit the migration file and build the index yourself. 您必须编辑迁移文件并自行构建索引。 Another thing that I just read, but haven't encountered, is that the MySQL driver does not allow multiple connections which may mean changing the way you retrieve async collections. 我刚刚阅读但未遇到的另一件事是MySQL驱动程序不允许多个连接,这可能意味着改变了检索异步集合的方式。 Lastly, I had a problem with RowVersion being a byte[]. 最后,我遇到RowVersion是byte []的问题。 I used a variation from the following article to solve this (hopefully!). 我使用了以下文章中的变体来解决这个问题(希望如此!)。

Better way to implement a row version with EF Core and MySQL? 使用EF Core和MySQL实现行版本的更好方法是什么?

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

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