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

2019-08-01 04:38发布

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

2条回答
聊天终结者
2楼-- · 2019-08-01 05:41

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);
        }
    }
查看更多
兄弟一词,经得起流年.
3楼-- · 2019-08-01 05:41

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.

查看更多
登录 后发表回答