/// <summary> /// Method called by the consumers of this service when an execution exception occurs. /// It is used to handle edge cases where cleaning up is required. /// NOTE: This method should handle the exception and not rethrow it. /// </summary> /// <param name="e">Exception thrown during execution.</param> /// <param name="cmd">Command that was running when the exception was raised.</param> /// <param name="reader">Reader created from executing the command, if applicable.</param> /// <param name="conn">Connection that creates the transaction where the exception occurred, if applicable.</param> /// <param name="trans">Transaction where the exception was produced, if applicable.</param> /// <param name="manager">Transaction manager associated with this command, if applicable.</param> public virtual void OnExecuteException(DbException e, IDbCommand cmd, IDataReader reader, IDbConnection conn, IDbTransaction trans, ITransactionManager manager) { if (IsConnectionException(e)) { // #70408, #112391 // When network connection is lost and later recovered to the database all previous connections in the pool // become unusable. Connection opening works as expected, but once used the following exception will occur: // - TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host. // There is no viable workaround to this problem (except for disabling connection pooling) // http://social.msdn.microsoft.com/Forums/en-US/sqlnetfx/thread/4895d56b-716f-4f82-860f-0aa161d327cc/ // This will affect ALL connections in the connection pool. // Our workaround is to release all connections in the pool when the error happens. Although the current call // will fail, subsequent errors like this will be avoided since new connections will have to be opened. DatabaseServices.TransactionService.ReleasePooledConnections(e.Message); // Close reader if open if (reader != null && !reader.IsClosed) { reader.Close(); } if (manager != null && trans != null) { manager.AbortTransaction(trans); } } }
private void InstallFixture(ITransactionManager transactionManager, IContainerInjector injector, object fixture) { injector.InitDomainObject(fixture); // first, install any child fixtures (if this is a composite. var childFixtures = GetFixtures(fixture); InstallFixtures(transactionManager, injector, childFixtures); // now, install the fixture itself try { Log.Info("installing fixture: " + fixture); transactionManager.StartTransaction(); InstallFixture(fixture); transactionManager.EndTransaction(); Log.Info("fixture installed"); } catch (Exception e) { Log.Error("installing fixture " + fixture.GetType().FullName + " failed (" + e.Message + "); aborting fixture ", e); try { transactionManager.AbortTransaction(); } catch (Exception e2) { Log.Error("failure during abort", e2); } throw; } }
public Task AbortTransaction(long transactionId, OrleansTransactionAbortedException reason) { tm.AbortTransaction(transactionId, reason); return(Task.CompletedTask); }