2013-01-18 33 views
1

C#/SQLite app工作正常,但輸出這個錯誤偶爾:SQLite的錯誤(10):延遲25ms的鎖定/共享衝突

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

至於建議就this thread,我更新到最新的SQLite的,但它仍然發生。
如何解決這個問題?


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

的Visual C#2010速成

+0

值得一試,如果你是封閉的SqliteConnections在使用語句確保他們被處置。 – gls123

+0

@GavinSinai:我一直無法找到它發生的地方(因爲它似乎隨機發生),但我只在這個類中使用SQLite:https://github.com/nicolas-raoul/CmisSync/blob/master/ SparkleLib/Cmis/CmisDatabase.cs –

回答

1

從這個原代碼:

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

這可能會緩解問題,但其他因素可能會導致此錯誤顯示。

+0

更改爲此後,它表示'不能訪問已處理的對象。對象名稱:SQLiteConnection' –

+0

我不想每次都重新創建SQLiteConnection連接,所以不能使用這個想法。 –

+0

我發現我可以完全消除我的system.data.sqlite代碼中的這種錯誤,確保所有連接,命令和讀者都在使用語句中。 – gls123