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

旧巷老猫 提交于 2019-12-11 10:07:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!