我有以下代码:
string sql = String.Format("insert into {0}({1}) values({2});", tableName, columns, values);
SQLiteConnection myConn = null;
try
{
myConn = new SQLiteConnection(dbConnection);
myConn.Open();
using(SQLiteCommand sqCommand = new SQLiteCommand(sql, myConn))
{
sqCommand.CommandText = sql;
int rows = sqCommand.ExecuteNonQuery();
return !(rows == 0);
}
}
finally
{
myConn.Close();
}
它总是返回错误:Database is locked
行:
int rows = sqCommand.ExecuteNonQuery();
Whu会发生吗?
答案 0 :(得分:2)
我敢打赌,当sqCommand.ExecuteNonQuery()
方法执行时(锁仍然适用于以前的连接),数据库连接在某处保持打开状态,因此您需要通过包装每个 {{1}来重构带有SQLiteConnection
语句块的实例,如下所示:
using
参考: