|
Is there a simple way to detect if a transaction for a given name is open? For example in this code, I need to know whether to rollback the transaction in the error handler.
(comments are locked)
|
|
A ROLLBACK will always roll back the outermost transaction. SQL Server doesnt yet support nested transactions (in the sense we are talking about here). If you are already in the context of a transaction, and you BEGIN TRANSACTION, you dont truly open a new transaction scope, you really just increment that @@trancount counter. Any subsequent COMMIT will decrement it, but only the final COMMIT actually commits it. ref link Im not positive what you are trying to do here, but you may want to look into SAVE TRAN which will let you rollback to a predefined save point. BOL link
(comments are locked)
|
|
You can query the @@TRANCOUNT variable to determine how nested transactions are currently open. I usually do something like: I thought about that, but won't this break if I call this proc from another proc that has the call wrapped in another transaction?
Mar 04 '10 at 02:10 PM
JohnFx
(comments are locked)
|
|
You should be able to see the open transaction in sys.dm_tran_active_transactions. You may need to narrow it down more using sys.dm_exec_sessions to get the specific session.
(comments are locked)
|

