“无法找到或加载已注册的 .Net Framework 数据提供程序”与 MySQL +网络平台

发布于 2024-08-26 08:13:05 字数 235 浏览 4 评论 0原文

我们该如何修复这个问题?这个问题在互联网上已经被多次讨论过,但这始终是一种解决方法。始终将 MySql.data.dll 复制到您的 bin 目录中,或明确说明您想要的版本。将 DbProvderFactory for MySQL 与 ASP.NET 结合使用的“正确”方法是什么?

我希望能够在本地进行开发,而不用担心他们在服务器上安装了什么版本。就目前情况而言,如果我确实复制了自己的版本,我必须确保它是他们使用的版本。看起来很容易坏。

How do we repair this? This question has been sort of addressed many times around the internet, but it's always a workaround. Always copying the MySql.data.dll into your bin directory, or explicitly stating what version you want. What is the "proper" approach to using DbProvderFactory for MySQL with ASP.NET?

I'd like to be able to develop locally and not worry what version they have installed on the server. As it stands, if I do copy up my own version I have to make sure it's the one they use. Seems easy to break.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

天煞孤星 2024-09-02 08:13:06

类似线程上的用户注意到了此错误的另一个原因 此处 我已复制粘贴下面的用户答案,以防链接发生更改

我刚刚看到在我的情况下出现此异常的原因是 dll 和配置条目之间的版本不同。
因此,有时您实际拥有的 dll(通过 nuget 或其他方式安装)与 app.config 节点中的条目不同。如果 app.config 中没有此部分,也可以在下面找到
Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config 和附近的文件夹。
更改 dll 版本条目中的版本解决了该问题。

Another reason for this error was noted by a user on a similar thread here I have copy pasted the users answer below in case the link changes

I just saw that the reason of this exception in my case were the differt versions between dll and the configuration entry.
So, sometimes the dll you actually have (either installed by nuget or other way) differs from the entry in the node of the app.config. This section, if not in app.config, can be also found under
Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config and nearby folders.
Changing version in the entry to version of the dll solved the issue.

月牙弯弯 2024-09-02 08:13:06

以下是我如何让 MySQL 连接器工作:

在 DbProviderFactories 下的 machine.config 中添加以下内容:

<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.7.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />

*请注意,版本号和 PublicKeyToken 将根据您安装的 MySQL 连接器的版本而有所不同。此示例适用于 v6.7.4.0 和 v2.0 dot net

下一个副本 %Program Files%\MySQL\MySQL Connector Net 6.7.4\Assemblies\v2.0\MySql.Data.dll

%Windows\程序集。

希望这对某人有帮助:)

Here how I got the MySQL connector to work:

In the machine.config under DbProviderFactories add the folliwng:

<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.7.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />

*Note the version number and PublicKeyToken will be different depending on the version of the MySQL connector you have installed. This example is for v6.7.4.0 and v2.0 dot net

Next copy %Program Files%\MySQL\MySQL Connector Net 6.7.4\Assemblies\v2.0\MySql.Data.dll
to
%Windows\assembly.

Hope this helps someone :)

永言不败 2024-09-02 08:13:06

另一种无需 app.config 的代码方式:(不要忘记在此代码中设置正确的 MySql.Data 版本)

  public class MySqlDbConfiguration: DbConfiguration 
{
    public MySqlDbConfiguration()
    {
        SetDefaultConnectionFactory(new MySqlConnectionFactory());
        SetProviderServices(MySqlProviderInvariantName.ProviderName, new MySqlProviderServices());
        RegisterFactoryIfRequired();
    }

    private static void RegisterFactoryIfRequired()
    {
        string dataProvider = @"MySql.Data.MySqlClient";
        string dataProviderDescription = @".Net Framework Data Provider for MySQL";
        string dataProviderName = @"MySQL Data Provider";
        string dataProviderType =
            @"MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d";

        bool addProvider = true;
        var dataSet = ConfigurationManager.GetSection("system.data") as DataSet;
        foreach (DataRow row in dataSet.Tables[0].Rows)
        {
            if ((row["InvariantName"] as string) == dataProvider)
            {
                // it is already in the config, no need to add.
                addProvider = false;
                break;
            }
        }

        if (addProvider)
            dataSet.Tables[0].Rows.Add(dataProviderName, dataProviderDescription, dataProvider, dataProviderType);

        // test it
        var factory = DbProviderFactories.GetFactory("MySql.Data.MySqlClient");
    }

}

Another way through code without app.config: (don't forget to set the right MySql.Data version in this code)

  public class MySqlDbConfiguration: DbConfiguration 
{
    public MySqlDbConfiguration()
    {
        SetDefaultConnectionFactory(new MySqlConnectionFactory());
        SetProviderServices(MySqlProviderInvariantName.ProviderName, new MySqlProviderServices());
        RegisterFactoryIfRequired();
    }

    private static void RegisterFactoryIfRequired()
    {
        string dataProvider = @"MySql.Data.MySqlClient";
        string dataProviderDescription = @".Net Framework Data Provider for MySQL";
        string dataProviderName = @"MySQL Data Provider";
        string dataProviderType =
            @"MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d";

        bool addProvider = true;
        var dataSet = ConfigurationManager.GetSection("system.data") as DataSet;
        foreach (DataRow row in dataSet.Tables[0].Rows)
        {
            if ((row["InvariantName"] as string) == dataProvider)
            {
                // it is already in the config, no need to add.
                addProvider = false;
                break;
            }
        }

        if (addProvider)
            dataSet.Tables[0].Rows.Add(dataProviderName, dataProviderDescription, dataProvider, dataProviderType);

        // test it
        var factory = DbProviderFactories.GetFactory("MySql.Data.MySqlClient");
    }

}
眼眸里的那抹悲凉 2024-09-02 08:13:05

如果相关程序集不在 GAC 中,则它必须存在于路径(即 bin 文件夹)中。必须在 GAC 大会上签字。我猜测 MySql.data.dll 的构建者没有签署该 dll,因此您可能无法将其放入服务器上的 GAC 中。因此,复制 dll 是您的解决方案。

If the assembly in question is not in the GAC, then it does have to exist in the path, i.e. the bin folder. The be in the GAC, the assembly has to be signed. I'm guessing the the builders of MySql.data.dll did not sign the dll so you may not be able to put it into the GAC on the server. So copying the dll is your solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文