SqlTransaction and Dispose

  • Thread starter Thread starter Wells Caughey
  • Start date Start date
W

Wells Caughey

I have looked in the documentation and I have looked in Google, but I cannot
seem to find an answer: If a transaction has been opened and the transaction
is disposed before calling Commit or Rollback, am I guarenteed that the
transaction will be rolled back? For example:

try
{
sqlConnection.Open();
using(sqlTransaction = sqlConnection.BeginTransaction())
{
/// do stuff but do not call sqlTransaction.Commit() or
sqlTransaction.Rollback()
/// ...
} /// <- will the transaction be rolled back here?
}
finally
{
sqlConnection.Close();
}

Thanks,
Wells
 
Thanks for the reply Nicole. Rolling back a transaction on Dispose is what
I expected, but I just needed that verification...

Wells
 
Back
Top