views:

62

answers:

1

I accidentally found zombie transaction is mentioned in SqlTransaction code. So, what is zombie transaction?

+4  A: 

A zombie transaction is a transaction that cannot be committed (due to an unrecoverable error) but is still open.

CREATE TABLE mytable (id INT NOT NULL PRIMARY KEY)
SET XACT_ABORT ON;
BEGIN TRY
        BEGIN TRANSACTION
                INSERT
                INTO    mytable
                VALUES  (1)
                INSERT
                INTO    mytable
                VALUES  (1)
        COMMIT
END TRY
BEGIN CATCH
        PRINT XACT_STATE()
        SELECT  *
        FROM    mytable
        ROLLBACK;
END CATCH
SELECT  *
FROM    mytable

Here, the second INSERT renders the transaction zombie.

It cannot write anymore and should be rolled back, but you can still read in its scope (the innermost SELECT returns a record; the outermost does not).

Quassnoi
And you need a machete or shotgun to get rid of it!...Man, I love I.T. work. 80)
Keng
Do you prefer an axe or a baseball bat?
Mitch Wheat