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

Announcements

No record found.

News and Announcements icon
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 12

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

I have the same question (0)
  • Verified answer
    Mea_ Profile Picture
    60,286 on at

    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.

  • nickgt Profile Picture
    12 on at

    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,

  • Martin Dráb Profile Picture
    239,392 Most Valuable Professional on at

    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
    12 on at

    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.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 39

#2
Michel ROY Profile Picture

Michel ROY 14

#3
imran ul haq Profile Picture

imran ul haq 8

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans