C
Cole Shelton
Hi all,
I have a question about transactions and exceptions. I wrote some code that
would handle an exception and rollback a transaction. e.g.
SqlTransaction tran = null;
try {
tran = conn.BeginTran();
// Execute Update, Inserts etc..
tran.Commit();
}
Catch(Exception e)
{
tran.Rollback();
}
However, when a SqlException occurs, i get an exception on the rollback line
saying that no corresponding transaction can be found. I am assuming that a
SqlException automatically causes the Transaction to Rollback? Is this
Correct?
So, if that is the case, I will want to only do a rollback when I catch a
non-SqlException?
Please let me know how you guys handle these situations.
Thanks
Cole
I have a question about transactions and exceptions. I wrote some code that
would handle an exception and rollback a transaction. e.g.
SqlTransaction tran = null;
try {
tran = conn.BeginTran();
// Execute Update, Inserts etc..
tran.Commit();
}
Catch(Exception e)
{
tran.Rollback();
}
However, when a SqlException occurs, i get an exception on the rollback line
saying that no corresponding transaction can be found. I am assuming that a
SqlException automatically causes the Transaction to Rollback? Is this
Correct?
So, if that is the case, I will want to only do a rollback when I catch a
non-SqlException?
Please let me know how you guys handle these situations.
Thanks
Cole