Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Query regarding error behaviour with SqlBatch #3792

Answered by benrr101
rkaushik15 asked this question in Q&A
Discussion options

Hello!

I had some queries regarding error handling with SqlBatch.

From my local tests I can observe the following behavior:

With default case - SqlBatch.Transaction is null, in case any statement in the batch fails, the changes from non-failing DMLs in the batch get committed.
QUESTION:
Is my understanding correct? Does the SqlBatch.Execute* API internally create a local transaction to rollback or commit the changes?

If SqlBatch.Transaction is NOT null, and a statement in the batch fails, even the non-failing DML changes are not committed.
QUESTION:
Is my understanding correct? Does the provider automatically rollback the changes in case an error is encountered? And will it automatically commit when no errors are there?

Thanks in advance.

You must be logged in to vote

In general your understanding is correct - however, if there is a transaction, it shouldn't be automatically committed. You would need to commit the transaction when you've finished executing the changes.

But as @Wraith2 said, you may need to try it and experiment a bit. We need to update our docs to give a better understanding of this behavior to developers.

Replies: 2 comments

Comment options

Try it and see? I expect it depends on the exact definition of the sql server interaction between batches and transactions so thing like xact_abort can change it.

You must be logged in to vote
0 replies
Comment options

In general your understanding is correct - however, if there is a transaction, it shouldn't be automatically committed. You would need to commit the transaction when you've finished executing the changes.

But as @Wraith2 said, you may need to try it and experiment a bit. We need to update our docs to give a better understanding of this behavior to developers.

You must be logged in to vote
0 replies
Answer selected by cheenamalhotra
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
Area\Documentation Use this for issues that requires changes in public documentations/samples.
Converted from issue

This discussion was converted from issue #3273 on November 21, 2025 06:18.

AltStyle によって変換されたページ (->オリジナル) /