/// <summary> /// Creates a connection to the database informed. /// </summary> /// <param name="dbName">Enumeration of type <see cref="DatabaseName"/>.</param> private void InitDbConnection(DatabaseName dbName) { if (IsEnlisted) { return; } if (CurrentConnection != null && CurrentConnection.State != ConnectionState.Closed && CurrentConnection.State != ConnectionState.Broken) { //if there is a connection opened to another db, throw an exception if (CurrentDbName != dbName) { throw new DatabaseException($"The repository cannot request a connection to database '{dbName}' because it possesses an open connection to database {CurrentDbName}."); } //auto-rollback on dispose if (CurrentTransaction?.Connection != null) { CurrentTransaction.Rollback(); } if (CurrentConnection.State != ConnectionState.Closed || CurrentConnection.State != ConnectionState.Broken) { CurrentConnection.Close(); CurrentConnection = null; } } CurrentConnection = Context.CreateConnection(dbName); CurrentDbName = dbName; }
public void Transaction(Action action) { lock (this.SyncLock) { this.AssertValid(); EnsureTransaction(); try { CurrentTransaction.Enlist(); action(); CurrentTransaction.Leave(); } catch (Exception) { CurrentTransaction.Rollback(); throw; } finally { if (!CurrentTransaction.Running) { CurrentTransaction = null; } } } }
public void RollBackTransaction() { using (CurrentTransaction) { CurrentTransaction.Rollback(); } }
/// <summary> /// 回滚事务 /// </summary> public void Rollback() { if (IsEnabledTransaction) { CurrentTransaction.Rollback(); } HasCommitted = true; }
public void Rollback() { if (CurrentTransaction != null) { CurrentTransaction.Rollback(); CurrentTransaction = null; } }
/// <summary> /// Discards all changes made to the database in the current transaction. /// </summary> public virtual void RollbackTransaction() { if (CurrentTransaction == null) { throw new InvalidOperationException(RelationalStrings.NoActiveTransaction); } CurrentTransaction.Rollback(); }
public void Rollback() { CurrentTransaction?.Rollback(); CurrentTransaction?.Dispose(); if (CurrentConnection?.State == ConnectionState.Open) { CurrentConnection.Close(); } CurrentConnection?.Dispose(); }
/// <summary> /// Rolls back a transaction. /// </summary> /// <returns></returns> public virtual bool rollBack() { if (CurrentTransaction == null) { throw new PDOException("No active transaction"); } CurrentTransaction.Rollback(); CurrentTransaction = null; return(true); }
public void RollbackTransaction( ) { if (CurrentTransaction == null) { throw new InvalidOperationException("Can not commit a transaction that has not been started."); } CurrentTransaction.Rollback(); CurrentTransaction = null; }
/// <summary> /// 事务回滚 /// </summary> public void Rollback() { if (CurrentTransaction == null) { return; } CurrentTransaction.Rollback(); CurrentTransaction.Dispose(); CurrentTransaction = null; }
/// <summary> /// Rolls back a transaction. /// </summary> /// <returns></returns> public virtual bool rollBack() { if (CurrentTransaction == null) { HandleError("No active transaction"); return(false); } CurrentTransaction.Rollback(); CurrentTransaction = null; return(true); }
public void Rollback() { if (CurrentTransaction == null) { throw new InvalidOperationException(); } lock (_transactionSyncRoot) { CurrentTransaction.Rollback(); CurrentTransaction.Dispose(); CurrentTransaction = null; } }
public void RollbackTransaction() { try { CurrentTransaction?.Rollback(); } finally { if (CurrentTransaction != null) { CurrentTransaction.Dispose(); CurrentTransaction = null; } } }
public void RollbackTransaction() { if (!HasOpenTransation()) { throw new Exception("Não existe transação aberta"); } try { CurrentTransaction.Rollback(); CurrentTransaction = null; } finally { CloseSession(); } }
public override void Complete() { lock (_lock) { _db.SaveChanges(); if (CurrentTransaction != null) { try { CurrentTransaction.Commit(); } catch (System.Exception) { CurrentTransaction.Rollback(); } finally { CurrentTransaction.Dispose(); } } } }
/// <summary> /// 释放资源 /// </summary> /// <param name="disposing"></param> protected virtual void Dispose(bool disposing) { if (!_isDisposed) { if (Connection != null) { using (Connection) { if (Connection.State != ConnectionState.Closed) { if (CurrentTransaction != null) { CurrentTransaction.Rollback(); CurrentTransaction.Dispose(); } } Connection.Close(); Connection.Dispose(); } } this._isDisposed = true; } }
// Protected implementation of Dispose pattern. protected virtual void Dispose(bool disposing) { if (disposed) { return; } if (disposing) { if (_connection is object) { if (CurrentTransaction is object) { if (!_committed) { CurrentTransaction.Rollback(); } CurrentTransaction.Dispose(); } _connection.Dispose(); } } disposed = true; }
public override void RollbackTransaction() => CurrentTransaction.Rollback();
public void RollbackTransaction() => CurrentTransaction.Rollback();
public void RollbackTransaction() { CurrentTransaction?.Rollback(); }