//这是我的连接数据库(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();
}
}
}
答案 0 :(得分:0)
尝试SslMode=None;
。如果您可以提供抛出的异常,将很有用。
确定您指定了在服务器上运行的MySql实例的端口吗?它是否在默认端口3306上运行?