简体   繁体   English

如何在 Visual Studio for Mac 上连接 MySQL DB

[英]How to connect MySQL DB on Visual Studio for Mac

I have already tried to add SQLClient reference我已经尝试添加 SQLClient 引用

using System.Data.SqlClient 

But still I got these errors但我仍然收到这些错误

I have been using macOS我一直在使用 macOS

它

Open the solutionExplorer , go to references , right click on it and choose add reference .打开solutionExplorer ,转到references ,右键单击它并选择add reference Now browse for the assembly SqlClient and hit the ok button.现在浏览程序集SqlClient并点击确定按钮。


But using the using statement in your code just saves you some additional words in order to shorten and simplify your code.但是在您的代码中using语句只会为您节省一些额外的单词,以便缩短和简化您的代码。 Imagine if you would have added a reference of the assembly System.Data.SqlClient to your project, but didn't write using System.Data.SqlClient;想象一下,如果您将程序集System.Data.SqlClient的引用添加到您的项目中,但没有using System.Data.SqlClient;编写using System.Data.SqlClient; , then you could still create a new SqlConnection object, but you have to add like an address , which assembly shell be used. ,那么您仍然可以创建一个新的SqlConnection对象,但是您必须像地址一样添加,使用哪个程序集外壳。

System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();

But importing the reference needs to be done manual, a few basic assembly references have already been added by default, that's why但是导入引用需要手动完成,默认情况下已经添加了一些基本的程序集引用,这就是为什么

using System.Web.Mcv;

knows which referenced assembly is meant.知道哪个引用的程序集是指。 For clarification, have a look at the referenced assemblies in your project and you will find System.Web.Mcv there, so it has been added there already.为澄清起见,请查看项目中引用的程序集,您会在那里找到System.Web.Mcv ,因此它已添加到那里。

You need to add the MySQL.Data dll via nuget manager您需要通过 nuget 管理器添加 MySQL.Data dll

在此处输入图片说明

After that use it as usual,之后照常使用,

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM