web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

X++ transation

(0) ShareShare
ReportReport
Posted on by 113

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.pastedimage1673598564862v2.png

I have the same question (0)
  • Tracy wang Profile Picture
    113 on at

    Because I have no environment test, if not rollback, what can be done

  • Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at

    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?

  • Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at

    Also what is the exception you are getting?

  • Tracy wang Profile Picture
    113 on at

    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?

  • Tracy wang Profile Picture
    113 on at

    I'm just giving you an example, if i  change  int a=1/0  to try  catch, it will be  rollback?

  • Verified answer
    Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at

    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.

  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at

    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.

  • Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at

    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.

  • Tracy wang Profile Picture
    113 on at
    • What you mean is that a transaction must cover any code that might have an exception?

      [quote user="Tracy wang"]

      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.pastedimage1673598564862v2.png

      [/quote]

  • Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at

    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.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 512 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 291 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans