I am trying to troubleshoot blocking problems related to active open transaction with sleeping status and probably have found issues related to XACT ABORT option missing or as OFF read from many blog post online–
-
Is there a way to find what stored procs are missing those
statements for a database? -
As SQL by default has this off, is there a harm enabling at SQL
instance to ON or is it recommended to have only some SP to turn
this on as. Why i am asking because as mentioned here it seems
this should be added to all SP as best practice, is that true? if
yes why not enable this at SQL instance level?
Best Answer
This query will show you all T-SQL modules (i.e. stored procedures, functions, etc) on a SQL Server instance that have
XACT_ABORT
in their code:One could rewrite that to show code without
XACT_ABORT
present, by simply addingNOT
to theWHERE
clause, as in:However, you'll notice there are several possibilities for false positives:
XACT_ABORT
in the code./* must not use XACT_ABORT in this code */
etc.
To be honest, your question sounds like an XY problem. Are you sure you want to determine which code uses
XACT_ABORT
? A stored procedure won't cause an open transaction to "hang around". The most likely cause is a code window open in SSMS that hasBEGIN TRANSACTION
where the correspondingROLLBACK
orCOMMIT
haven't been executed. Alternately, there could be some legitimate long-running code keeping transactions open. One common issue that results in long running transaction is code using the RBAR method.Regarding your second question, I'd be extremely reluctant to ever say a particular set statement should "always" be used, although I do tend to use
SET XACT_ABORT = ON
a lot. Erland Sommarskog is very highly regarded in the SQL Server community, but I don't agree with this: