ASP.NET 和 MySQL .Net Framework 数据提供程序问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8062282/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 21:36:44  来源:igfitidea点击:

ASP.NET and MySQL .Net Framework Data Provider Issues

asp.netmysql

提问by SiHyung Lee

I'm new in ASP.NET. Everytime I try to run my application, I encounter the error message below. I already installed .Net Framework Data Provider for MySQL several times. I hope someone can help me on this. Thanks in advance.

我是 ASP.NET 的新手。每次我尝试运行我的应用程序时,都会遇到以下错误消息。我已经多次为 MySQL 安装了 .Net Framework Data Provider。我希望有人可以帮助我。提前致谢。

Server Error in '/PLDT QuickSearcher' Application.

Unable to find the requested .Net Framework Data Provider.  It may not be installed.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentException: Unable to find the requested .Net Framework Data Provider.  It may not be installed.

回答by Filip

Add MySql.Data.dll as reference to the project
Add this block to web.config:

添加 MySql.Data.dll 作为对项目的引用
将此块添加到 web.config:

<system.data>
    <DbProviderFactories>
        <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory,MySql.Data" />
    </DbProviderFactories>
</system.data> 

回答by sky-dev

Reference the MySql.Data and MySql.Entities Nuget packages. Then add this line to your web config.

参考 MySql.Data 和 MySql.Entities Nuget 包。然后将此行添加到您的网络配置中。

<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.5.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
  </DbProviderFactories>
</system.data>

Your connection string should be similar to the following:

您的连接字符串应类似于以下内容:

<add name="MyDb" connectionString="Server=127.0.0.1;Port=3306;Database=MyDb;Uid=root;Pwd=;" providerName="MySql.Data.MySqlClient" />

回答by Konstantin Orlov

I have solved this problem with following configuration

我已经通过以下配置解决了这个问题

<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" />
    </DbProviderFactories>
  </system.data>

  <entityFramework>  
    <providers>
        <provider invariantName="MySql.Data.MySqlClient"
                  type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
    </providers>
  </entityFramework>