1
我的應用程序每3秒向一個SQLite
數據庫發出一個查詢,但大約20分鐘後,執行該命令時,它會拋出異常"Attempt to write a readonly database"
。我只需要讀取數據庫。試圖寫一個只讀數據庫經過20分鐘的重複查詢
進口:
using System.Data.Sqlite;
這是我的連接字符串:
sqlite_conn = new SQLiteConnection("Data Source=Patch_here;Version=3;Compress=True;Read Only=True"
這是投excepcion的方法。這種方法是執行每3秒:
Double fecha = 0;
try
{
sqlite_cmd = new SQLiteCommand(sqlite_conn);
sqlite_cmd.CommandText = "SELECT MAX(timestamp) FROM Messages";
//HERE throws the exception, when executes the command.
fecha = Double.Parse(sqlite_cmd.ExecuteScalar().ToString());
sqlite_cmd.Dispose();
}
catch (Exception ex)
{
informarError(ex.Message);
}
return timestamp_To_Datetime(fecha);
此外, - 我的用戶有這個數據庫的所有權限。 - 我的SQLiteConnection只是一次打開所有查詢。
我能做些什麼?謝謝。
爲什麼你明確調用Dispose而不使用'using'語句?如果發生錯誤,並且你進入了catch(Exception ex)塊,你永遠不會處理這個對象。此外,您不會顯示如何處理'SQLiteConnection',您應該與命令建立連接並進行處理,而不是在全局範圍內重新使用它。 ADO.NET專爲短暫連接而設計,而不是長期共享的連接。根據你的SQLite庫,它可能會實現連接池,所以連接將被重新使用。 –
我也嘗試過使用'using'語句,但不是解決方案。 我的SQLiteConnection只是一次打開所有查詢。 – user3569173