问题
My C#/SQLite app works fine but outputs this error once in a while:
SQLite error (10): delayed 25ms for lock/sharing conflict
As suggested on this thread, I updated to the latest SQLite, but it still happens.
How to fix this?
SQLite version: sqlite-netFx40-static-binary-Win32-2010-1.0.84.0.zip
at the Precompiled Statically-Linked Binaries for 32-bit Windows (.NET Framework 4.0)
paragraph at http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki
Visual C# 2010 Express
回答1:
From this original code:
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);
}
}
Changing to this solved the problem (only the first two lines differ):
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);
}
}
回答2:
Looking at the source code from your comment:
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);
}
}
The using statement is disposing the command and not the connection. Try using two nested using statements for each command.
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);
}
}
}
This may alleviate the problem, however other factors could cause this error to manifest.
来源:https://stackoverflow.com/questions/14394280/sqlite-error-10-delayed-25ms-for-lock-sharing-conflict