Query regarding error behaviour with SqlBatch #3792
-
|
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. If SqlBatch.Transaction is NOT null, and a statement in the batch fails, even the non-failing DML changes are not committed. Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
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. |
Beta Was this translation helpful? Give feedback.
-
|
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. |
Beta Was this translation helpful? Give feedback.
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.