【问题标题】:Connect to local MySql database using C# [duplicate]使用 C# 连接到本地 MySql 数据库 [重复]
【发布时间】:2018-03-09 20:59:41
【问题描述】:

我正在尝试连接到我的本地 MySQL 数据库,但我不确定所有参数是什么。希望有人可以提供帮助。

我的代码:

string connetionString = "Server = 127.0.0.1; Database = name of database; User Id = root, Password = password of database";

SqlConnection cnn = new SqlConnection(connetionString);

try
{
    cnn.Open();
    MessageBox.Show("Connection Open ! ");
    cnn.Close();
}
catch (Exception ex)
{
    MessageBox.Show(ex.ToString(), "titel", MessageBoxButtons.OK);
    MessageBox.Show("Can not open connection ! ");
}

谢谢

【问题讨论】:

  • 你得到什么错误信息?
  • Google 搜索需要 12 秒,创建 SO 问题需要 4 分钟。前者只会浪费你的时间,后者会浪费很多人的时间。 dotnetperls.com/sqlconnection
  • 您使用了错误的连接字符串和错误的实例。您应该使用MySql.Data.MySqlConnection 和链接上给出的连接字符串示例。
  • 如果您使用的是 MySQL,那么您必须使用 MySqlConnectionMySqlCommand 类 - 不能 SqlConnectionSqlCommand - 这些是仅限 SQL Server
  • @NielsSchutte 正如@marc_s & 我之前提到的,我建议您区分 SQL Server 和 MySQL 连接字符串,不要将它们混合使用。 MySQL 使用 MySql.Data.MySqlClient 命名空间,而 SQL Server 使用 System.Data.SqlClient 命名空间,它们不同

标签: c# mysql connection


【解决方案1】:

您可以尝试将连接字符串设置为

server=127.0.0.1;database={dbname};uid={};password=password@1;Max Pool Size=800;

【讨论】:

猜你喜欢
  • 2015-07-09
  • 1970-01-01
  • 1970-01-01
  • 2016-03-01
  • 1970-01-01
  • 2012-04-27
  • 1970-01-01
  • 1970-01-01
  • 2018-08-01
相关资源
最近更新 更多