|
@@ -15,10 +15,12 @@ namespace InABox.Database.SQLite
|
|
|
{
|
|
|
public SQLiteConnection Connection { get; private set; }
|
|
|
|
|
|
+ protected static int nConnections = 0;
|
|
|
+
|
|
|
public void Dispose()
|
|
|
{
|
|
|
- if (Connection != null)
|
|
|
- Connection.Close();
|
|
|
+ Connection?.Close();
|
|
|
+ --nConnections;
|
|
|
}
|
|
|
|
|
|
public SQLiteCommand CreateCommand()
|
|
@@ -33,12 +35,14 @@ namespace InABox.Database.SQLite
|
|
|
sb.Version = 3;
|
|
|
sb.DateTimeFormat = SQLiteDateFormats.Ticks;
|
|
|
sb.JournalMode = SQLiteJournalModeEnum.Wal;
|
|
|
+
|
|
|
var conn = sb.ToString();
|
|
|
|
|
|
Connection = new SQLiteConnection(conn);
|
|
|
Connection.BusyTimeout = Convert.ToInt32(TimeSpan.FromMinutes(2).TotalMilliseconds);
|
|
|
Connection.Open();
|
|
|
Connection.SetLimitOption(SQLiteLimitOpsEnum.SQLITE_LIMIT_VARIABLE_NUMBER, 10000);
|
|
|
+ ++nConnections;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -61,13 +65,17 @@ namespace InABox.Database.SQLite
|
|
|
{
|
|
|
Setup(url);
|
|
|
}
|
|
|
+ catch(Exception e)
|
|
|
+ {
|
|
|
+ throw new Exception($"Exception while acquiring write lock! {nConnections} connections open.", e);
|
|
|
+ }
|
|
|
finally
|
|
|
{
|
|
|
Monitor.Exit(writelock);
|
|
|
}
|
|
|
|
|
|
if (Connection == null)
|
|
|
- throw new Exception("Timeout while aqcuiring write lock!");
|
|
|
+ throw new Exception($"Timeout while aqcuiring write lock! {nConnections} connections open.");
|
|
|
}
|
|
|
|
|
|
public SQLiteTransaction BeginTransaction()
|