无法连接到任何指定的mysql主机

dfddblmv  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(266)

//这是我连接到数据库的代码(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();
        }
    }
}
kninwzqo

kninwzqo1#

尝试 SslMode=None; . 如果您能提供抛出的异常,这将非常有用。
您确定指定了服务器上运行的mysql示例的端口吗?它是否在默认端口3306上运行?

相关问题