为什么我不能使用 ef6 代码先更新数据库 mysql 迁移?

永远的蝙蝠侠29

首先使用ef6连接到godaddy上的MySql db来实现代码时遇到问题。它仍在尝试连接到 SQL 实例

运行时出现以下错误 update-database

错误编号:53,状态:0,类别:20 与 SQL Server 建立连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。(提供程序:命名管道提供程序,错误:40 - 无法打开与 SQL Server 的连接)

这是我的 app.config:

<xml version="1.0" encoding="utf-8">
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>
  <connectionStrings>
    <add name="LMScontext" connectionString="Server=servername;Database=dbname;Uid=user;Pwd=password;" providerName="MySql.Data.MySqlClient" />
  </connectionStrings>
  <entityFramework>

    <providers>
      <!--<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />-->
      <!--<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.10.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
    </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.10.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
  </system.data>
</configuration>
二书

在我的情况下可行的一种可能的解决方案是,

在正上方的行下方添加 <providers>.....</providers>

<defaultConnectionFactory type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data" />
<providers>
  ...
</providers>

然后<DbProviderFactories>.....</DbProviderFactories>web.config或 中删除部分app.config

然后将以下属性添加到DbContext类实现

[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]

所以它看起来像,

[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))] 
public class MySqlDbContext : DbContext 
{
    .....
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用EF6和.NET 4.6.1进行数据库迁移时遇到多个错误

为什么我不能使用MySQL Workbench连接到我的MySQL数据库?

EF6代码迁移-数据库不同,但相同

为什么我不能使用PHP发布到我的MySQL数据库?

使用EF6迁移失败重命名身份表

使用EF6迁移更改表之间的关系

具有单个数据库多个上下文的EF6代码优先迁移

使用EF6代码优先的MySQL现有数据库-带有脚手架的控制器创建错误

EF6代码迁移-数据操作以将列'filePath'更新为varbinary

EF6首先使用SQLite模型创建数据库

使用Pomelo EF net-core 3.0,数据库创建迁移时出错:MySql

如何使用代码首先迁移到更新数据库?

使用相同的数据库更新数据库后,是否可以删除 EF Core 数据库迁移?

无法创建实体数据模型-使用MySql和EF6

在 EF6 中使用数据注释

MySQL和EF6的ASP.NET Identity迁移问题

当我用EF6查询数据库时,使用LINQ有什么优势?

为什么我不能使用生成的名称进行迁移?

使桌面客户端可以使用更新的EF数据库迁移而无需更新

添加了EF6 / Mysql的数据库优先模式名称为XXY

无法使用EF6和MYSQL生成实体

如何避免先使用Entity Framework代码和现有数据库进行迁移?

如何在Azure上使用EF更新/迁移SQLite数据库

MySql数据库中的实体框架代码优先迁移

使用GCP的MySQL数据库迁移服务在迁移过程中出错

实体框架代码优先迁移在EF5中有效,但在EF6中无效

EF代码优先迁移,数据库生成GUID密钥

为什么我不能使用 Azure 移动应用更新我的数据库

MySQL数据库迁移丢失数据