如何通过 C# 使用 mysql 连接器连接到 mysql 而无需实际安装连接器
我们有一个基于dot net 2.0的C#产品,它使用Mysql作为数据存储。当我们在 XP/Win 7 计算机上安装 mysql 连接器 6.3.6 时,我们能够从 C# 代码连接到数据库,没有任何问题。但是当 mysql 连接器实际上没有安装在计算机上而只是存在于可执行文件的同一目录中时,我们在连接到 mysql 数据库时遇到了问题。我们不想在每台希望产品运行的机器上安装连接器。我们希望直接使用连接器 DLL,就像我们在代码中使用任何第 3 方 DLL(例如记录器)一样。
即使我们将 mysql.data.dll 复制到安装 exe 的同一目录中,它也会构建但不会连接到数据库。
给出的错误是
无法找到请求的 .Net Framework 数据提供程序。可能没有安装 块引用
技术信息:
- Mysql 5.0
- C#
- Dot Net Framework 2.0
- Mysql Connector 6.3.6(同样的问题出现在 sql 连接器的 6.0.3 版本中)
- Win XP/Win 7
当我们使用 ASP.Net 时,我们可以将下面给出的标签指定为web.config,我们可以通过将dll放入bin目录直接连接mysql数据库
<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#中为桌面上的客户端服务器应用程序做同样的事情 环境。
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.
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.
The error given is
Unable to find the requested .Net Framework Data Provider. It may not be installed
Blockquote
Technical Information:
- 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
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>
Why can't we do the same thing in the C# for the Client Server application in the desktop environment.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试这样的事情(我没有检查任何可能的版本/配置,但它目前在我的 Vista x64 for MySql some 5.5... 和 .net 连接器 6.4.3.0 - 使用 mysql.data.dll for v4 from .net /单声道下载)。
确保下面引用的 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).
Make sure the referenced mysql.data.dll assembly below is in your current directory.
此页面不会进入有关 .NET Framework 依赖项的更多详细信息,但我怀疑 Mysql 连接器可能依赖于更高版本的 .NET Framework。
换句话说,您的应用程序使用Framework 2,但是Mysql连接器使用什么版本?
This page doesn't go into much detail about .NET Framework dependency, but I suspect that the Mysql connector might be dependent on a later version of the .NET framework.
In other words, your application uses Framework 2, but what version does the Mysql connector use?
此条目:
... 需要写入您的 machine.config 中。
我相信默认路径应该是这样的:
更新
您应该能够将 MySQL .Net/Connector 安装程序包含在安装包中。需要 machine.config 中的条目的原因与 web.config 中需要信息的原因相同。
This entry:
... needs to be written into your machine.config.
I believe the default path should be something like:
Update
You should be able to include MySQL .Net/Connector installer as part of your installation package. The entry in the machine.config is required for the same reasons that information is required in a web.config.