简体   繁体   English

“不支持关键字” MySQL C#

[英]“Keyword not supported” MySQL C#

I am developing a WinForms application in c# and MySQL (server from GearHost) for data storage. 我正在用c#和MySQL(来自GearHost的服务器)开发WinForms应用程序以进行数据存储。 Now, I created a class to deal with SQL operations but everytime I call it my code throws the error "KeyWord not supported". 现在,我创建了一个用于处理SQL操作的类,但是每次调用它时,我的代码都会引发错误“不支持KeyWord”。 I've read other similar questions but found nothing that works with my code. 我读过其他类似的问题,但没有发现与我的代码兼容的内容。

string connectionString = @"datasource=mysql#.gear.host;port=3306;username=######;pwd=##########;database=########;";
MySqlConnection databaseConnection = new MySqlConnection(connectionString);

You can use the a connection string builder so you don't have to worry about mis-typing any of the keywords. 您可以使用一个连接字符串构建器,因此您不必担心输入任何关键字的方式都不正确。

var conn_string = new MySqlConnectionStringBuilder();
conn_string.Server = "######";
conn_string.UserID = "#######";
conn_string.Password = "#######";
conn_string.Database = "#######";

using (var conn = new MySqlConnection(conn_string.ToString()))
using (var cmd = conn.CreateCommand())
{
     cmd.CommandText = "your command text";
     conn.Open();
     cmd.ExecuteNonQuery();
}

Instead of: 代替:

string connectionString = @"datasource=mysql#.gear.host;port=3306;username=######;pwd=##########;database=########;";

Go with: 与:

string connectionString = @"server=mysql#.gear.host;port=3306;uid=########;password=########;database=########;";

More examples here: https://www.connectionstrings.com/mysql/ 此处有更多示例: https : //www.connectionstrings.com/mysql/

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

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