不知何故,MySQL突然不能执行查询后,这运行
本文关键字:查询 运行 执行 突然 何故 MySQL 不能 | 更新日期: 2023-09-27 18:12:54
public void saveImage(byte[] image, int patient_id, MySqlConnection con)
{
string sql = "select * from patient where id ="+patient_id;
DataSet ds = new DataSet("patient");
MySqlDataAdapter dAdapter = new MySqlDataAdapter(sql, con);
MySqlCommandBuilder builder = new MySqlCommandBuilder(dAdapter);
dAdapter.Fill(ds, "patient2");
try
{
ds.Tables["patient2"].Rows[0]["picture"] = image;
dAdapter.Update(ds, "patient2");
// ds.Tables["patient2"].Rows[0].AcceptChanges();
con.Close();
con.Open();
}
catch (Exception exs)
{
Console.WriteLine(exs.Message);
}
}
如何修复这个错误…在此执行之后,以下查询都不会在此之后工作…发生了什么事?我已经试过评论"con.close"answers"con.open"的方式了。
我怀疑发生这种情况是因为您关闭了连接,然后重新打开它。你不应该重新打开一个关闭的连接…实际上我很惊讶它没有扔出一个InvalidOperationException
。无论如何,如果你的方法接收到一个打开的连接作为参数,它不应该关闭它。打开连接的代码负责关闭连接