diff --git a/src/SQLite.Net/SQLiteConnection.cs b/src/SQLite.Net/SQLiteConnection.cs index 475a9aa8..f0716793 100644 --- a/src/SQLite.Net/SQLiteConnection.cs +++ b/src/SQLite.Net/SQLiteConnection.cs @@ -1135,9 +1135,29 @@ public void Commit() { if (Interlocked.Exchange(ref _transactionDepth, 0) != 0) { - Execute("commit"); + // Do nothing on a commit with no open transaction + + try + { + Execute("commit"); + } + catch (Exception) + { + // something went wrong. at least we should clean up + try + { + Execute("rollback"); + } + catch + { + // if rollback won't work (e.g. commit was already ok) just silent fail + // i did not see this, but just to be safe + } + + // and throw the original exception anyway + throw; + } } - // Do nothing on a commit with no open transaction } ///