Skip to main content

Notifications

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

  • Tracy wang Profile Picture
    Tracy wang 113 on at
    RE: X++ transation

    i  see,thank  you so much,I benefited a lot.

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,853 Most Valuable Professional on at
    RE: X++ transation

    No. You should include code (especially database operations) that should either complete successfully or all database changes should be rolled back. The purpose is to prevent inconsistent data changes. For example, imagine that you're deleting an order. You delete the header and when trying to delete lines, an error occur. You want to cancel the whole operation and therefore the delete of the order header must be rolled back. Otherwise you'd end up with lines without an order header. How likely it is that the deletion fails is irrelevant - what you need to consider what forms a single logical operation.

  • Tracy wang Profile Picture
    Tracy wang 113 on at
    RE: X++ transation

    thank you so much i  see

  • Verified answer
    Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,587 Super User 2024 Season 1 on at
    RE: X++ transation

    See. Simply give a try catch block and in try you can give the transaction. If it is success the execution won't go to catch block and record gets inserted. If some error, then execution comes to catch.

    It is not explicitly required to give error code in transaction so that it gives error in a transaction.

    As Martin suggested, if error comes with transaction means between ttsbegin commit then only transaction will fail or if exception happens before the transaction. Once it is committed there will be no issue on transaction with this exception.

  • Tracy wang Profile Picture
    Tracy wang 113 on at
    RE: X++ transation

    What I mean is that I only need to include the code that is likely to cause exceptions between ttsbegin and ttscommit, and nothing else

  • Martin Dráb Profile Picture
    Martin Dráb 230,853 Most Valuable Professional on at
    RE: X++ transation

    Sorrt, I don't understand what you're saying. Please elaborate.

  • Tracy wang Profile Picture
    Tracy wang 113 on at
    RE: X++ transation

    In my understanding, I would only put database operations between ttsbegin and ttscommit

  • Tracy wang Profile Picture
    Tracy wang 113 on at
    RE: X++ transation

    i know,But not all exceptions are ready to be caught, even if the server goes down just after the transaction has been committed

  • Martin Dráb Profile Picture
    Martin Dráb 230,853 Most Valuable Professional on at
    RE: X++ transation

    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.

  • Tracy wang Profile Picture
    Tracy wang 113 on at
    RE: X++ transation
    • 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]

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,996 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,853 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans