“提供者未返回ProviderManifestToken字符串"具有实体框架的MySQL [英] "The provider did not return a ProviderManifestToken string" MySQL with Entity Framework

查看:72
本文介绍了“提供者未返回ProviderManifestToken字符串"具有实体框架的MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have set up a new project in VS 2017. My intention is to use EF CodeFirst approach. So far I used Azure SQL Database, while in this test project I want to use my remote MySQL database. I have created the user and permissions are set just right. This remote database server is accessible to me over MySQL Workbench.

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

I have created a new blank MVC project and through Nuget I installed MySQL.Data.Entity (version 6.9.10).

我的上下文类:

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

    }

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

我的web.config具有以下条目:

My web.config has these entries:

<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命令时,我得到了

When I give Enable-Migrations -Force command, I get

检查上下文是否以现有数据库为目标... System.Data.Entity.Core.ProviderIncompatibleException:提供者 没有返回ProviderManifestToken字符串. ---> MySql.Data.MySqlClient.MySqlException:无法连接到任何 指定的MySQL主机.在 MySql.Data.MySqlClient.NativeDriver.Open()在 MySql.Data.MySqlClient.Driver.Open()在 MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder 设置) MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()在 MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()在 MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()在 MySql.Data.MySqlClient.MySqlPool.GetConnection()在 MySql.Data.MySqlClient.MySqlConnection.Open()在 MySql.Data.MySqlClient.MySqlProviderServices.GetDbProviderManifestToken(DbConnection 连接) System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection 连接)-内部异常堆栈跟踪的结尾-在 System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection 连接) MySql.Data.Entity.MySqlManifestTokenResolver.ResolveManifestToken(DbConnection 连接) System.Data.Entity.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection 连接,DbProviderManifest& providerManifest) System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)位于 System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)在 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
1 writeXml)在 System.Data.Entity.Utilities.DbContextExtensions.GetModel(DbContext 上下文) System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration 配置,DbContext usersContext,DatabaseExistenceState existState,布尔值,称为ByCreateDatabase,位于 System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration 配置) System.Data.Entity.Migrations.Design.MigrationScaffolder..ctor(DbMigrationsConfiguration migrationsConfiguration),位于 System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.RunCore() 在System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()处 提供者未返回ProviderManifestToken字符串.

Checking if the context targets an existing database... System.Data.Entity.Core.ProviderIncompatibleException: The provider did not return a ProviderManifestToken string. ---> MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the specified MySQL hosts. 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& providerManifest) at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) at System.Data.Entity.Internal.RetryLazy2.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 return a ProviderManifestToken string.

据我所知,我已经进行了广泛搜索,但无济于事.这里发生了什么事?我想念什么?

I have searched far and wide to the best of my knowledge to no avail. What's happening here? What am I missing?

推荐答案

我最近遇到了与您相同的问题.在SQL Server中一切正常,但是在转换为MySQL时遇到很多问题.对我有用的一些东西是:

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. Some things that worked for me are:

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

MySQL的较新的8.0软件包似乎有问题.当我恢复到旧版本时,它起作用了.

The newer 8.0 packages of MySQL appear to have problems. When I reverted to an older version, it worked.

您的app.config应该如下所示:

Your app.config should look like:

      <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 []有问题.我使用了以下文章的一种变体来解决此问题(希望如此!).

Even after that, there are some discrepancies in MySQL that I'm just finding out. 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. Lastly, I had a problem with RowVersion being a byte[]. I used a variation from the following article to solve this (hopefully!).

实现带有EF Core和MySQL的行版本?

这篇关于“提供者未返回ProviderManifestToken字符串"具有实体框架的MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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