Hi,
if i have two transactions inside try and catch and what i want is if the 2nd transaction failed then a retry should happen. How can i do that?
try { ttsbegin; //logic ttscommit; ttsbegin; //logic ttscommit; } catch { }
Aot/Macros/OCRRetryCount double click -->#define.RetryNum (5)
2. Like I already wrote, it's a macro. As a general suggestion - whenever you stumble upon a new word/idea, don't be afraid to search the web first - usually you'll find documentation, blogs and existing discussions. It's fast, and you don't need to wait or depend on anyone else to provide the initial information. Once you've digested the info, and still have some questions, then it's usually a good time to post a question.
docs.microsoft.com/.../xpp-macros
You can find the [tag:OCRRetryCount] macro in AOT and read yourself what's the value of [tag:RetryNum].
Hi Nikolaos,
1. you are right, i discovered that what i did is wrong because now if 1st transaction failed, it will go the confirmation and this is wrong.So i did it this way:
public void method() { try { ttsbegin; //create order; ttscommit; int retryCount =3; int currentCount = 0; try { ttsbegin; //confirm order; //assigning value ttscommit; } catch { currentCount ; if(currentCount <= retryCount) { retry; } } } catch { } }
2. I read on the web, that i should define this macro [tag:OCCRetryCount before using [tag:RetryNum.
so what does this [tag:OCCRetryCount mean? and what is the value of [tag:RetryNum?
Nope its not correct. In this code, even if the order creation gets an error, the confirm will work. Dont catch it or add the confirm to the try block
RetryNum in OCCRetryCount macro
1. You can find it out by debugging and testing your code. I think that's generally the best way to find out whether your exception handling is now correct or not.
2. # means that the value comes from a macro. You can find macros in AOT. Since there's no macro called #RetryNum, you might have missed some detail in your class where some macro is included, and actually #RetryNum is just something inside that AOT macro.
Hi Nikolaos and ergun,
Thanks both and no Nikolaos it's not a number sequence, it's just some logic where i get value from a table and this value can only be assigned to one record
1. can you please confirm that the logic i did here is correct? would this now let the order creation happen successfully even if the confirmation fails.And it will give a chance for the confirmation and assigning value to retry few times before failing. and is there anything that could go wrong using my way?
public void method() { try { ttsbegin; //create order; ttscommit; } catch { } int retryCount =3; int currentCount = 0; try { ttsbegin; //confirm order; //assigning value ttscommit; } catch { currentCount ; if(currentCount <= retryCount) { retry; } } }
2. is there a better way for specifying the counter?i guess there is sth like this:xSession::currentRetryCount() >= #RetryNum but how can idefine the RetryNum?
You can use the first example you have written yourself. In the first example, if you do not retry outside, the code will not repeat in case of order creation error. (When it receives an error in order creation, it will not proceed until confirm)
No the case you're talking about is not a deadlock, it's a logical error
1. Then the order creation and confirmation should be in different transactions and different try-catch statements. But I'm not sure if your retry will ever fix the issue that you're having. Of course it fully depends on details that we don't know so we can't really comment on that. You are the expert of your functionality, we don't know almost anything about it.
2. Not sure what these values are, but if you talk about number sequences, then the system handles it quite well any many users will not get same values. If you have implemented something similar yourself, but ended up with worse solution that doesn't work - perhaps that's a decision that you should question. Otherwise also your users would experience similar issues and would have to often retry things manually.
"is that considered a deadlock?". No, deadlocks are deadlocks.
Hi Nikolaos and Ergun,
1. So let's say in the first transaction, i create an order. If it is done successfully. Then i want to confirm the order in the 2nd transaction.
I don't want the confirm order to happen unless the order creation is done successfully. However if the confirmation failed it shouldn't affect the order creation but i will retry the confirmation few times in case it failed. So how should i put my try and catch based on this? should they be two separate ones or one inside the other or sth different.
2. About the retry. Yes i'm expecting it to solve itself that's why i want to do a retry.
So let's say in the 2nd transaction after confirming the order, i select first only and take a value from a table and assign it somewhere. so if two people clicked at the same time, both of them will take the same record but the one who clicked by a fraction of a second earlier will take the value and the other one will fail because it took a value that is already taken because when assigning the value it will say that it got assigned somewhere else, so a retry will select first only again and take sth new. is that considered a deadlock? or should i use a normal catch?
I guess we wrote it at the same time, you didn't see me write on top
"it doesn't actually make much sense to write a retry command for any error. Something must have changed the second time the code ran (Deadlock, UpdateConflict..etc.)"
Of course, you can use the counter to get out of the endless loop, but why try again if something won't change.
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 Andrés Arias as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Sohaib Cheema 882 User Group Leader
André Arnaud de Cal... 723 Super User 2025 Season 2
CA Neeraj Kumar 518