【问题标题】:Unable to connect to any of the specified MySql host无法连接到任何指定的 MySql 主机
【发布时间】:2018-12-25 22:44:38
【问题描述】:

//这是我连接数据库的代码(xampp)

private void runQuery()
{
    String ConnectionString = "Server=myServerAddress;Database=myDatabase;Uid=myUsername;Pwd=myPassword;";

    MySqlConnection connection = new MySqlConnection(ConnectionString);
    connection.Open();
    try
    {
        MySqlCommand cmd = connection.CreateCommand();
        cmd.CommandText = "Select * from stockcard";
        MySqlDataAdapter adap = new MySqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        adap.Fill(ds);
        dataGridView1.DataSource = ds.Tables[0].DefaultView;

    }
    catch (Exception e)
    {
        throw;
    }
    finally
    {
        if(connection.State == ConnectionState.Open)
        {
            connection.Clone();
        }
    }
}

【问题讨论】:

  • 你能告诉我们抛出的异常信息是什么吗?
  • “无法连接到任何指定的 MySQL 主机。”

标签: c# mysql database xampp


【解决方案1】:

试试SslMode=None;。如果您可以提供抛出的异常,将会很有用。

您确定您指定了服务器上运行的 MySql 实例的端口吗?它是否在默认端口 3306 上运行?

【讨论】:

  • 您尝试过使用 SslMode none 吗?
  • 更重要的是,您的服务器在线吗?
  • 你怎么知道它是否在线?
  • 尝试启动它:sudo /opt/lampp/lampp start
猜你喜欢
  • 2011-06-07
  • 2013-08-02
  • 2017-02-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-20
相关资源
最近更新 更多