//这是我连接到数据库的代码(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();
}
}
}
1条答案
按热度按时间kninwzqo1#
尝试
SslMode=None;
. 如果您能提供抛出的异常,这将非常有用。您确定指定了服务器上运行的mysql示例的端口吗?它是否在默认端口3306上运行?