diff --git a/src/Orchard/Data/SessionLocator.cs b/src/Orchard/Data/SessionLocator.cs index cb28a46ec..c0a3966f3 100644 --- a/src/Orchard/Data/SessionLocator.cs +++ b/src/Orchard/Data/SessionLocator.cs @@ -66,19 +66,26 @@ namespace Orchard.Data { void IDisposable.Dispose() { if (_transaction != null) { - if (!_cancelled) { - Logger.Debug("Marking transaction as complete"); - _transaction.Commit(); - } - else { - Logger.Debug("Reverting operations from transaction"); - _transaction.Rollback(); - } + try { + if (!_cancelled) { + Logger.Debug("Marking transaction as complete"); + _transaction.Commit(); + } + else { + Logger.Debug("Reverting operations from transaction"); + _transaction.Rollback(); + } - _transaction.Dispose(); - Logger.Debug("Transaction disposed"); - - _cancelled = false; + _transaction.Dispose(); + Logger.Debug("Transaction disposed"); + } + catch (Exception e) { + Logger.Error(e, "Error while disposing the transaction."); + } + finally { + _transaction = null; + _cancelled = false; + } } }