SQLite错误(10):锁定/共享冲突延迟25ms

时间:2013-01-18 07:29:34

标签: c# sqlite locking conflict

我的C#/SQLite app工作正常但偶尔输出此错误:

SQLite error (10): delayed 25ms for lock/sharing conflict

根据this thread的建议,我更新了最新的SQLite,但它仍然会发生 如何解决这个问题?


SQLite版本sqlite-netFx40-static-binary-Win32-2010-1.0.84.0.zip位于http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wikiPrecompiled Statically-Linked Binaries for 32-bit Windows (.NET Framework 4.0)

Visual C#2010 Express

2 个答案:

答案 0 :(得分:2)

从这段原始代码:

    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);
        }
    }

答案 1 :(得分:0)

查看评论中的源代码:

        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);
        }
     }
  }

这可以缓解这个问题,但是其他因素可能会导致此错误出现。