简体   繁体   English

将现有的 .NET 实体框架层从 Sql Server 更改为 MySql

[英]Change existing .NET Entity Framework layer from Sql Server to MySql

Question : I have an web application that uses .NET Entity Framework library to access a Sql Server Database.问题:我有一个 Web 应用程序,它使用 .NET Entity Framework 库来访问 Sql Server 数据库。 What should I do to change it to MySQL ?我应该怎么做才能将其更改为 MySQL?

Some more details更多细节

I tried changing the parameters in app.config and here is my app.config file.我尝试更改 app.config 中的参数,这是我的 app.config 文件。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- 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>
  <connectionStrings>
    <add name="mysql_db" connectionString="server=localhost;user id=root;password=;database=foo" providerName="MySql.Data.MySqlClient" />
  </connectionStrings>
  <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.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
     </providers>
  </entityFramework>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
</configuration>  

I ran the app after using the above file and I get the following error.使用上述文件后,我运行了该应用程序,但出现以下错误。

A network-related or instance-specific error occurred while establishing a connection to SQL Server.与 SQL Server 建立连接时发生与网络相关或特定于实例的错误。 The server was not found or was not accessible.服务器未找到或无法访问。 Verify that the instance name is correct and that SQL Server is configured to allow remote connections.验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。 (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (提供程序:命名管道提供程序,错误:40 - 无法打开与 SQL Server 的连接)

What else should I change to make it use a MySQL database.我还应该更改什么以使其使用 MySQL 数据库。 I have installed the necessary tools (MySQL, .NET MySQL Connector, MySQL for Visual Studio).我已经安装了必要的工具(MySQL、.NET MySQL 连接器、Visual Studio 的 MySQL)。

I think you should install MySQL Connector/Net and the configure a proper connection string (this is a sample) Here you can find doc x ef6我认为您应该安装 MySQL Connector/Net 并配置正确的连接字符串(这是一个示例) 在这里您可以找到 doc x ef6

        <connectionStrings>
            <add name="MyContext" providerName="MySql.Data.MySqlClient" 
                connectionString="server=localhost;port=3306;database=mycontext;uid=root;password=********"/>
        </connectionStrings>
        <entityFramework>
            <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, 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"/>
            </providers>
        </entityFramework>

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

相关问题 在实体框架中从SQL Server告诉MySQL - Telling MySQL from SQL Server in Entity Framework 使用Entity Framework 6支持SQL Server更改跟踪 - Support SQL Server change tracking with Entity Framework 6 SQL 实体框架服务器 - SQL Server for Entity Framework 实体框架从MySQL迁移到SQL Server,并且表名缺少“ dbo” - Entity Framework migration from MySQL to SQL Server and the Table names missing “dbo” sql server /实体框架。 .net 3.5中的呼叫存储功能 - sql server / entity framework. call store function from .net 3.5 如何在不使用实体框架的情况下使用ASP NET MVC5从SQL Server显示表? - How to display table from SQL Server using ASP NET MVC5 without using Entity Framework? Net Core:Entity Framework 和 SQL 服务器临时表,自动脚手架 - Net Core: Entity Framework and SQL Server Temporal Tables, Automatic Scaffolding 在SQL Server的.NET / Entity Framework中设置事务隔离级别 - Setting Transaction Isolation Level in .NET / Entity Framework for SQL Server 带有 SQL 服务器存储过程的 Entity Framework.Net 6 – 未提供参数 - Entity Framework .Net 6 with SQL Server stored procedure – parameter not supplied NET 6 - 实体框架核心错误:SQL 服务器未找到或无法访问 - NET 6 - Entity Framework Core Error: SQL Server was not found or was not accessible
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM