I accidentally found zombie transaction is mentioned in SqlTransaction code. So, what is zombie transaction?
Asked
Active
Viewed 1.4k times
10
Andrew Bezzub
- 15,744
- 7
- 51
- 73
1 Answers
10
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
- 413,100
- 91
- 616
- 614
-
3And you need a machete or shotgun to get rid of it!...Man, I love I.T. work. 80) – Keng Oct 28 '10 at 13:47