1

我的C#/SQLite 应用程序运行良好,但偶尔会输出此错误:

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

正如这个线程所建议的,我更新到了最新的 SQLite,但它仍然会发生。
如何解决这个问题?


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

Visual C# 2010 速成版

4

2 回答 2

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);
        }
    }
于 2013-01-23T05:01:46.970 回答
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);
        }
     }
  }

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

于 2013-01-18T10:11:54.403 回答