How to handle busy event
(1) By Mr Tea (mr_tea) on 2020-09-18 10:19:11 [source]
I have an update statement which works fine generally however if 2 people update at the same time nothing gets updated in the database. I have had to set transaction lock to over come this but I was wondering how I can use the sqlite3_busy_timeout() in this code?
protected void UpdateDatabase(int id) { String rd = DateTime.Now.ToString("yyyy'-'MM'-'dd HH:mm:ss");
String ConnString = GetConnectSQLite();
if (io == "o")
io = "i";
else if (io == "i")
io = "o";
try
{
using (SQLiteConnection m_dbConnection = new SQLiteConnection(ConnString))
{
String sql = "UPDATE tblx SET io=?,stime=?,loc=?,ns=? WHERE ID =" + id;
using (SQLiteCommand cmd = new SQLiteCommand(sql, m_dbConnection))
{
cmd.Parameters.AddRange(new SQLiteParameter[]
{
new SQLiteParameter("io", io),
new SQLiteParameter("stime",rd),
new SQLiteParameter("loc",getLoc()),
new SQLiteParameter("ns","no"),
});
m_dbConnection.Open();
cmd.ExecuteNonQuery();
m_dbConnection.Close();
}
}
}
catch (Exception ex)
{
}
finally
{
TransactionUnlock();
if (io == "o")
Response.Redirect("somewhere");
else if(io == "i")
Response.Redirect("somewhere");
}
}