【发布时间】: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 主机。”