Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

pessimistic locking with an inbound port

(0) ShareShare
ReportReport
Posted on by 10

I have a problem where I want to lock a sales agreement header record while it is being updated by a class that is called from in inbound port, the reason is that the system that calls the inbound port is multi-threaded so there could be 2 or more sessions trying to update the same sales agreement and the processing can take a second or two so I don't want the other thread starting until the first one has ended.

I've tried putting a pessimistic locking select on the agreement header in the class but it doesn't seem to be working, I can still select and update the same sales agreement from another session when it should be locked.

Am I missing something, can you not do this in a class attached to an inbound port, i'm assuming that the whole inbound instance of the class is already in a TTS transaction so I don't need on in my class ?

thanks.

*This post is locked for comments

  • nickgt Profile Picture
    nickgt 10 on at
    RE: pessimistic locking with an inbound port

    Hey Martin,  I can create the locks and it works perfectly if I just run the code in the regular AX session as you suggested.  Its when I try and run the same code in the class that the inbound port calls (and debugged it in VS)  it doesn't seem to work correctly, it executed the pessimistic read and the record is locked, but as soon as I press F10 to the next statement in the code the lock is released and the other process can start updating the record.  I'll review the code, i must be missing something.

  • Martin Dráb Profile Picture
    Martin Dráb 231,321 Most Valuable Professional on at
    RE: pessimistic locking with an inbound port

    Your statement that pessimistic locking in AX doesn't work sounds suspicious. Are you saying that exclusive locks are not taken at all? In that case, I would review your implementation. For testing purposes, create a simple runnable class trying to obtain a lock, make sure it stops processing before completing the transaction (e.g. by stopping on a breakpoint) and then run the same thing again. You should either reproduce the problem or prove that this works.

    Can't the conflicting updates be at a different place than where you switched to pessimistic concurrency control?

    Regarding the current TTS level, you can simply review it in debugger.

  • nickgt Profile Picture
    nickgt 10 on at
    RE: pessimistic locking with an inbound port

    yeah, its a strange requirement and I've tried several ways of using the standard code but when I get two inbound requests at exactly the same time for the same agreement thats when chaos ensues as they lock each other out and update exceptions get generated as the two processes try to update the same record, and other associated records in other tables.  I'll take a look at the class you suggested,

  • Verified answer
    Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: pessimistic locking with an inbound port

    It's a very strange requirement, ideally you want to write your code in a way it won't compete for one record, but to answer your question, you don't need to lock agreement header, you can look something else. Look at ReqReaderWriterLock class as an example, first thread place a sql lock and everyone lese just wait it to be released.

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…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,321 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans