Notifications
Announcements
No record found.
hello,guys .if in a class ,The transaction has just been committed,next then the Excepction occur in,The previous transaction will still roll-back? as shownbelow, when program walking to int a=1/0,Excepection occured.
Because I have no environment test, if not rollback, what can be done
No the transaction will commit. It won't roll back. But why are you trying to divide a number by 0? It will surely cause exception. Can you tell the exact requirement?
Also what is the exception you are getting?
for example, i use odata calling other people's interface, and commit my transation,but when walking other people's service ,it occured excepction.it should be roll-back,isn't it?
I'm just giving you an example, if i change int a=1/0 to try catch, it will be rollback?
The transaction is already committed at line 6, therefore your code at line 7 has no impact on it.
If you want the exeption to rollback the transaction, put your logic inside the transaction.
Once a transaction means code between ttsbegin and commit is run successfully without error and if you get an error as suggested above then the saved transaction or record won't roll back or delete as transaction is committed. If the error comes before ttscommit due to any validation or something then record won't even save at all. So there is no transaction roll back concept from my knowledge. Either transaction won't happen or will happen that's it.
Hope you understood.
If you want to play around the code you can make the said changes in your code and try.
A transaction rollback means undoing changes already done (such as reverting updated records) so you can reach the state as if nothing happened.
Details of how it's actually implemented by SQL Server / Azure SQL are quite complicated, but we don't need to worry about them.
What you mean is that a transaction must cover any code that might have an exception?
I don't know what is so difficult on it. An exception aborts a transaction only if it's thrown in a transaction. Your 'throw' statement isn't in a transaction and therefore there is no transaction it could influence.
If update() (line 5) threw an exception, the transaction would be rolled back, because update() *is* called inside a transaction.
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Martin Dráb 660 Most Valuable Professional
André Arnaud de Cal... 512 Super User 2025 Season 2
Sohaib Cheema 291 User Group Leader