如何连接通过C#中使用MySQL的连接器,而无需实际安装连接器到mysql [英] How to connect to mysql using mysql connector via C# without actually installing the connector

查看:233
本文介绍了如何连接通过C#中使用MySQL的连接器,而无需实际安装连接器到mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个点网2.0的C#它使用MySQL作为数据存储产品。当我们安装XP / Win 7的机器上的MySQL Connector 6.3.6,我们都能够连接到从C#代码数据库中没有任何问题。但是,我们同时连接到MySQL数据库时,实际上并没有在机器上安装MySQL连接器,但只是存在于同一个目录下的可执行面临的一个问题。我们不希望安装我们想要的产品上运行的每个连接器和每一台机器。我们希望connectory DLL为我们使用我们的代码任何第三方DLL(如记录仪)可以直接使用。

We have a dot net 2.0 based C# product which uses Mysql as the data storage. When we install the mysql connector 6.3.6 on the XP/Win 7 machine, we are able to connect to the database from the C# code without any issues. But we are facing a problem while connecting to the mysql database when the mysql connector is actually not installed on the machine but is just present in the same directory as the executable. We don't want to install the connector on each and every machine we want the product to run on. We want the connectory dll to be used directly as we use any 3rd party dll (e.g logger) in our code.

甚至当我们复制到mysql.data.dll安装了exe文件在同一目录下,它构建但不连接到数据库。

Even when we copy the mysql.data.dll into the same directory where the exe is installed, it builds but does not connect to the database.

给出的误差

无法找到请求的.NET Framework数据提供程序。它可能没有安装
块引用

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

技术信息:


  • MySQL 5.0中

  • C#

  • 点网框架2.0

  • 的MySQL Connector

  • 赢XP / Win 7的

  • Mysql 5.0
  • C#
  • Dot Net framework 2.0
  • Mysql Connector 6.3.6 (same problem occurs with ver 6.0.3 of sql connector)
  • Win XP/Win 7

当我们使用ASP.Net,我们可以指定下面给出入web.config中的标签,我们可以直接把DLL到bin目录

When we are using ASP.Net, we can specify the tag given below into the web.config, and we can connect to mysql database directly by putting the dll into the bin directory

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






我们为什么不能做同样的事情在在C#在桌面环境中的客户端服务器应用程序。


Why can't we do the same thing in the C# for the Client Server application in the desktop environment .

任何帮助,非常感谢。

黑毡帽

推荐答案

尝试是这样的(我没有检查任何可能的版本/配置,但是目前它的作品在我的Vista 64位的MySQL的一些5.5 ...和.NET连接器6.4.3.0 - 使用从.NET /单声道下载V4)mysql.data.dll

Try something like this (I didn't check any possible versions/configurations, but it works currently on my Vista x64 for MySql some 5.5... and .net connector 6.4.3.0 - using mysql.data.dll for v4 from .net/mono download).

确认引用的MySQL。下面data.dll组件在当前目录。

Make sure the referenced mysql.data.dll assembly below is in your current directory.


using(var dt = new DataTable()) {
    dt.Columns.Add("Name");
    dt.Columns.Add("Description");
    dt.Columns.Add("InvariantName");
    dt.Columns.Add("AssemblyQualifiedName");
    dt.Rows.Add("Mysql something", 
        "mysql more", 
        "mysqlClient",
        "MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.4.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d");

    var f = DbProviderFactories.GetFactory(dt.Rows[0]);
    using(var conn = f.CreateConnection()) {
        conn.ConnectionString = "your string here";
        conn.Open();
        // and do your work here.
        Console.WriteLine(conn);
    }
}

这篇关于如何连接通过C#中使用MySQL的连接器,而无需实际安装连接器到mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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