简体   繁体   English

我缺少什么将我的 C# 代码连接到 MySQL 数据库

[英]what i am missing to connect my C# code to MySQL database

im very likely missing some obvious setup, im using XAMPP following a beginner project tutorial to make database, however i am getting an error System.ArgumentException : 'Option not supported.我很可能错过了一些明显的设置,我使用 XAMPP 按照初学者项目教程制作数据库,但是我收到错误System.ArgumentException :'Option not supported。 at

private MySqlConnection connection = new MySqlConnection("datasource:127.0.0.1;port=3306;username=root;password=;database=Csharp_Hotel_DB");

i already did search how to connect to MySQL but found no different than what said tutorial did:我已经搜索了如何连接到 MySQL 但发现与上述教程没有什么不同:

-add MySql.Data.dll as reference, -添加 MySql.Data.dll 作为参考,

- using MySql.Data.MySqlClient; - using MySql.Data.MySqlClient;

-making empty table at localhost/phpmyadmin via XAMPP - 通过 XAMPP 在 localhost/phpmyadmin 制作空表

and then test the connection with if(table.Rows.Count > 0) {MessageBox.Show("Yes");} else {MessageBox.Show("No");} assigned to a button.然后使用分配给按钮的if(table.Rows.Count > 0) {MessageBox.Show("Yes");} else {MessageBox.Show("No");}测试连接。 the program works but clicking the button give error message above.该程序可以工作,但单击按钮会在上面给出错误消息。

According to the example I found here (and an additional resource I often consult here for different RDBMSs I encounter), the parameters in your connection string are mis-named:根据我在此处找到的示例(以及我经常在此处为遇到的不同 RDBMS 咨询的附加资源),您的连接字符串中的参数命名错误:

datasource:127.0.0.1;port=3306;username=root;password=;database=Csharp_Hotel_DB

It should be:它应该是:

Server=127.0.0.1;Port=3306;Uid=root;Pwd=;Database=Csharp_Hotel_DB

It looks like you may be formatting the connection string based on MS SQL Server standards instead.看起来您可能正在根据 MS SQL 服务器标准格式化连接字符串。 Most C# examples you find online will likely have that since it's the same vendor.您在网上找到的大多数 C# 示例可能都有,因为它是同一供应商。 But the connection string depends on the RDBMS, not on the language connecting to it.但是连接字符串取决于 RDBMS,而不是连接到它的语言。 Which in this case is MySQL.在这种情况下是 MySQL。

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

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