Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Comments] THROW command is non-terminating across linked servers #14

Open
chadbaldwin opened this issue Apr 2, 2021 · 2 comments
Open
Labels

Comments

@chadbaldwin
Copy link
Owner

https://chadbaldwin.net/2021/04/02/throw-non-terminating-with-linked-server.html

@EitanBlumin
Copy link

Have you tried enabling the arithabort and xact_abort settings?
Those two can help when using nested execution contexts.

@chadbaldwin
Copy link
Owner Author

@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.

@chadbaldwin chadbaldwin changed the title [Comments] THROW command is non-terminating across linked servers THROW command is non-terminating across linked servers Aug 13, 2021
@chadbaldwin chadbaldwin changed the title THROW command is non-terminating across linked servers [Comments] THROW command is non-terminating across linked servers Aug 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants