如何添加对 .NET 的 MySQL 连接器的引用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1102281/
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 13:38:46  来源:igfitidea点击:

How do I add a reference to the MySQL connector for .NET?

.netmysql

提问by srinivas

What does this mean: Next add reference to: MySql.Data

这是什么意思:接下来添加对:MySql.Data 的引用

actually I have downloaded mysql connector/net. by following these instructions:

实际上我已经下载了 mysql 连接器/网络。按照以下说明操作:

First, you need to install the mysql connector/net, it is located at: http://dev.mysql.com/downloads/connector/net/1.0.html

首先,你需要安装mysql connector/net,它位于:http: //dev.mysql.com/downloads/connector/net/1.0.html

Next create a new project

接下来创建一个新项目

Next add reference to: MySql.Data

接下来添加引用:MySql.Data

Next add "using MySql.Data.MySqlClient;" but im not able to install the connector.

接下来添加“使用 MySql.Data.MySqlClient;” 但我无法安装连接器。

website:http://bitdaddys.com/MySQL-ConnectorNet.html

网站:http: //bitdaddys.com/MySQL-ConnectorNet.html

回答by Rob

"Add a reference to MySql.Data.dll" means you need to add a library reference to the downloaded connector. The IDE will link the database connection library with your application when it compiles.

“添加对 MySql.Data.dll 的引用”意味着您需要添加对下载的连接器的库引用。IDE 将在编译时将数据库连接库与您的应用程序链接起来。

Step-by-Step Example

分步示例

I downloaded the binary (no installer) zip package from the MySQL web site, extracted onto the desktop, and did the following:

我从 MySQL 网站下载了二进制(无安装程序)zip 包,解压缩到桌面,并执行以下操作:

  1. Create a new project in Visual Studio
  2. In the Solution Explorer, under the project name, locate References and right-click on it. Select "Add Reference".
  3. In the "Add Reference" dialog, switch to the "Browse" tab and browse to the folder containing the downloaded connector. Navigate to the "bin" folder, and select the "MySql.Data.dll" file. Click OK.
  4. At the top of your code, add using MySql.Data.MySqlClient;. If you've added the reference correctly, IntelliSense should offer to complete this for you.
  1. 在 Visual Studio 中创建一个新项目
  2. 在解决方案资源管理器中,在项目名称下,找到引用并右键单击它。选择“添加引用”。
  3. 在“添加引用”对话框中,切换到“浏览”选项卡并浏览到包含下载的连接器的文件夹。导航到“bin”文件夹,然后选择“MySql.Data.dll”文件。单击确定。
  4. 在代码的顶部,添加using MySql.Data.MySqlClient;. 如果您已正确添加引用,IntelliSense 应该会为您完成此操作。

回答by Lyon

In Visual Studio you can use nuget to download the latest version. Just right click on the project and click 'Manage NuGet Packages' then search online for MySql.Data and install.

在 Visual Studio 中,您可以使用 nuget 下载最新版本。只需右键单击项目并单击“管理 NuGet 包”,然后在线搜索 MySql.Data 并安装。

回答by user733584

When you download the connector/NET choose Select Platform = .NET & Mono (not windows!)

当您下载连接器/NET 时,请选择 Select Platform = .NET & Mono(不是 Windows!)

回答by Khatab Omer

As mysql official documentation:

作为mysql官方文档:

Starting with version 6.7, Connector/Net will no longer include the MySQL for Visual Studio integration. That functionality is now available in a separate product called MySQL for Visual Studio available using the MySQL Installer for Windows (see http://dev.mysql.com/tech-resources/articles/mysql-installer-for-windows.html).

从 6.7 版开始,Connector/Net 将不再包含用于 Visual Studio 集成的 MySQL。该功能现在可在名为 MySQL for Visual Studio 的单独产品中使用,该产品使用适用于 Windows 的 MySQL 安装程序可用(请参阅http://dev.mysql.com/tech-resources/articles/mysql-installer-for-windows.html)。

Online Documentation:

在线文档:

MySQL Connector/Net Installation Instructions

MySQL 连接器/网络安装说明

回答by delliottg

This is an older question, but I found it yesterday while struggling with getting the MySQL Connector reference working properly on examples I'd found on the web. I'm working with VS 2010 on Win7 64 bit but have to work with .NET 3.5.

这是一个较旧的问题,但我昨天在努力使 MySQL 连接器参考在我在网上找到的示例上正常工作时发现了它。我正在 Win7 64 位上使用 VS 2010,但必须使用 .NET 3.5。

As others have stated, you need to download the .Net & Mono versions (I don't know why this is true, but it's what I've found works). The link to the connectors is given above in the earlier answers.

正如其他人所说,您需要下载 .Net 和 Mono 版本(我不知道为什么这是真的,但我发现这是可行的)。前面的答案中给出了连接器的链接。

  • Extract the connectors somewhere convenient.
  • Open the project in Visual Studio, then on the menu bar navigate to Solution Explorer (View > Solution Explorer), and choose Properties (first box on the far left of the toolbar. The Solution Explorer shows up in the top right pane for me, but YMMV).
  • In Properties, select References & locate the instance for mysql.data. It's likely to have a yellow bang on it (Yellow triangle with exclamation point in it). Remove it.
  • Then on the menu bar, navigate to Project > Add Reference... > Browse > point to where you downloaded the connectors. I have only been able to get the V2 version to work, but that may be a factor of my platform, not sure.
  • Clean & build your application. You should now be able to use the MySQL connectors to talk to your database.
  • You can also now downgrade your .NET instance if you need to (we're constrained to .NET 3.5, but mysql.data.dll wants 4.0 at the time of my writing this). On the menu bar, navigate to the properties of your project (Project > Properties). Choose the Application tab > Target framework > Choose which .NET framework you want to use. You have to build the application at least once before you can change the .NET framework. Once you built once the connector will no longer complain about the lower version of .NET.
  • 将连接器提取到方便的地方。
  • 在 Visual Studio 中打开项目,然后在菜单栏上导航到解决方案资源管理器(视图 > 解决方案资源管理器),然后选择属性(工具栏最左侧的第一个框。解决方案资源管理器显示在我的右上角窗格中,但YMMV)。
  • 在“属性”中,选择“引用”并找到 mysql.data 的实例。它很可能有一个黄色的爆炸声(黄色三角形,里面有感叹号)。去掉它。
  • 然后在菜单栏上,导航到 Project > Add Reference... > Browse > 指向您下载连接器的位置。我只能让 V2 版本工作,但这可能是我的平台的一个因素,不确定。
  • 清理并构建您的应用程序。您现在应该能够使用 MySQL 连接器与您的数据库通信。
  • 如果需要,您现在还可以降级 .NET 实例(我们仅限于 .NET 3.5,但在我撰写本文时 mysql.data.dll 需要 4.0)。在菜单栏上,导航到项目的属性(项目 > 属性)。选择应用程序选项卡 > 目标框架 > 选择要使用的 .NET 框架。您必须至少构建一次应用程序,然后才能更改 .NET 框架。一旦你构建了一次连接器就不会再抱怨 .NET 的低版本了。