You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@EitanBlumin Nice! Good call on XACT_ABORT that works too. Before testing it, I didn't think it would make a difference because I wasn't using transactions, but it worked!
I just read the documentation for XACT_ABORT and I see this:
The THROW statement honors SET XACT_ABORT. RAISERROR does not. New applications should use THROW instead of RAISERROR.
That explains why this works. That's really interesting. To test this even further, instead of using THROW, I used RAISERROR and tested severity levels 0-19 (20+ kills the connection), and to my surprise (exactly as the documentation said), it did not terminate execution.
Which brings up another really important thing to know... If you're calling a stored procedure, and it uses RAISERROR('Error Message',16,1) (which is the same severity level used by THROW), not only will it not stop execution, but it will even ignore XACT_ABORT ON.
I was hoping XACT_ABORT ON would be a nice clean solution for all cases. But it seems a TRY/CATCH/THROW block is still the best way to go.
I tested ARITHABORT, though I didn't expect this to do anything since I wasn't throwing an overflow or div/0 error, and the test confirmed my expectations. It didn't make a difference in this case when using THROW to raise the exception.
changed the title [-][Comments] THROW command is non-terminating across linked servers[/-][+]THROW command is non-terminating across linked servers[/+]on Aug 13, 2021
changed the title [-]THROW command is non-terminating across linked servers[/-][+][Comments] THROW command is non-terminating across linked servers[/+]on Aug 13, 2021
Activity
EitanBlumin commentedon Apr 7, 2021
Have you tried enabling the arithabort and xact_abort settings?
Those two can help when using nested execution contexts.
chadbaldwin commentedon Apr 8, 2021
@EitanBlumin Nice! Good call on
XACT_ABORT
that works too. Before testing it, I didn't think it would make a difference because I wasn't using transactions, but it worked!I just read the documentation for
XACT_ABORT
and I see this:That explains why this works. That's really interesting. To test this even further, instead of using
THROW
, I usedRAISERROR
and tested severity levels 0-19 (20+ kills the connection), and to my surprise (exactly as the documentation said), it did not terminate execution.Which brings up another really important thing to know... If you're calling a stored procedure, and it uses
RAISERROR('Error Message',16,1)
(which is the same severity level used byTHROW
), not only will it not stop execution, but it will even ignoreXACT_ABORT ON
.I was hoping
XACT_ABORT ON
would be a nice clean solution for all cases. But it seems aTRY/CATCH/THROW
block is still the best way to go.I tested
ARITHABORT
, though I didn't expect this to do anything since I wasn't throwing an overflow or div/0 error, and the test confirmed my expectations. It didn't make a difference in this case when usingTHROW
to raise the exception.[-][Comments] THROW command is non-terminating across linked servers[/-][+]THROW command is non-terminating across linked servers[/+][-]THROW command is non-terminating across linked servers[/-][+][Comments] THROW command is non-terminating across linked servers[/+]