Personalized Community is here!
Quickly customize your community to find the content you seek.
Choose your path Increase your proficiency with the Dynamics 365 applications that you already use and learn more about the apps that interest you. Up your game with a learning path tailored to today's Dynamics 365 masterminds and designed to prepare you for industry-recognized Microsoft certifications.
Visit Microsoft Learn
2020 Release Wave 2Discover the latest updates and new features to Dynamics 365 planned through March 2021.
Release overview guides and videos Release Plan | Preview 2020 Release Wave 2 TimelineWatch the 2020 Release Wave 1 virtual launch event
The FastTrack program is designed to help you accelerate your Dynamics 365 deployment with confidence.
FastTrack Program | Finance TechTalks | Customer Engagement TechTalks | Upcoming TechTalks
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 ?
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.
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,
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.
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.
Business Applications communities