SqlTransaction question

  • Thread starter Thread starter WALDO
  • Start date Start date
W

WALDO

Once a SqlTransaction object has been committed or rolledback, can the
object still be used?

The reason I ask is because I am building a class that uses a
SqlTransaction object. It has methods that would use the same
transaction. When the user is done, they would call my commit method,
which would commit my SqlTransaction object. What would happen if they
tried to use one of thse same methods AFTER the transaction has been
committed? Would it crash? Would it ignore it? Should I dispose and
destroy my SqlTransaction object upon commitment?
 
You will get an InvalidOperationException if you try to call any of the
transaction methods after you have committed or rolled back. This is listed
in the docs for SqlTransaction under Exceptions.
 
WALDO said:
Once a SqlTransaction object has been committed or rolledback, can the
object still be used?

The reason I ask is because I am building a class that uses a
SqlTransaction object. It has methods that would use the same
transaction. When the user is done, they would call my commit method,
which would commit my SqlTransaction object. What would happen if they
tried to use one of thse same methods AFTER the transaction has been
committed? Would it crash? Would it ignore it? Should I dispose and
destroy my SqlTransaction object upon commitment?

Yes, dispose the transaction instance asap.
 
Cool. As I suspected. I will destroy then. Thank you.

(I'm assuming this is NOT the case with a partial rollback though,
correct?)
 
Back
Top