SQLite错误(10):锁/共享冲突导致延迟25ms
本文关键字:冲突 共享 25ms 延迟 错误 SQLite | 更新日期: 2023-09-27 17:54:01
我的c#/SQLite应用程序工作正常,但偶尔输出此错误:
SQLite error (10): delayed 25ms for lock/sharing conflict
根据这个线程的建议,我更新到最新的SQLite,但它仍然发生。
如何解决这个问题?
SQLite版本:sqlite-netFx40-static-binary-Win32-2010-1.0.84.0.zip
在Precompiled Statically-Linked Binaries for 32-bit Windows (.NET Framework 4.0)
段在http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki
从原始代码:
using (var command = new SQLiteCommand(GetSQLiteConnection()))
{
try
{
command.CommandText =
"DELETE FROM folders WHERE path='" + path + "'";
command.ExecuteNonQuery();
}
catch (SQLiteException e)
{
SparkleLogger.LogInfo("CmisDatabase", e.Message);
}
}
改成这样就解决了问题(只有前两行不同):
var connection = GetSQLiteConnection();
using (var command = new SQLiteCommand(connection))
{
try
{
command.CommandText =
"DELETE FROM folders WHERE path='" + path + "'";
command.ExecuteNonQuery();
}
catch (SQLiteException e)
{
SparkleLogger.LogInfo("CmisDatabase", e.Message);
}
}
查看您的注释中的源代码:
using (var command = new SQLiteCommand(GetSQLiteConnection()))
{
try
{
command.CommandText =
"DELETE FROM folders WHERE path='" + path + "'";
command.ExecuteNonQuery();
}
catch (SQLiteException e)
{
SparkleLogger.LogInfo("CmisDatabase", e.Message);
}
}
using语句处理的是命令而不是连接。尝试为每个命令使用两个嵌套using语句。
using (var connection= GetSQLiteConnection())
{
using (var command = new SQLiteCommand(connection))
{
try
{
command.CommandText =
"DELETE FROM folders WHERE path='" + path + "'";
command.ExecuteNonQuery();
}
catch (SQLiteException e)
{
SparkleLogger.LogInfo("CmisDatabase", e.Message);
}
}
}
这可能会缓解问题,但其他因素可能导致此错误出现。