Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Locking /deadlock in Ax2012 (delete_from in BatchServer

(0) ShareShare
ReportReport
Posted on by 1,535

I’m changing process to multi-thread process. I changed process with class Thread and working ok, now I want to change using Batch Server (class run on a server, CIL). I have a problem with multiple batches at the same time. Problem is a deadlock.

Batch1:
Delete_from Tab1 exists join Tab2 where Tab1.id = Tab2.id and Tab2.Group=’AAA’

Batch2:
Delete_from Tab1 exists join Tab2 where Tab1.id = Tab2.id and Tab2.Group=’BBB’

 

In this scenario I have a problem (infolog):
Cannot delete a record in @... (Tab1). Deadlock, where one or more users have simultaneously locked the whole table or part of it.

Microsoft.Dynamics.Ax.Xpp.DeadlockException: Exception of type 'Microsoft.Dynamics.Ax.Xpp.DeadlockException' was thrown. at Microsoft.Dynamics.Ax.MSIL.Interop.throwException(Int32 ExceptionValue) at Microsoft.Dynamics.Ax.MSIL.cqlCursorIL.DeleteAll(IntPtr table)

   at Dynamics.Ax.Application….() in ….xpp:line …

 

After changing my methods like below everything is OK:

Batch1:

Select forUpdate Tab1 exists join Tab2 where Tab1.id = Tab2.id and Tab2.Group=’AAA’

{ Tab1.doDelete()}

Batch2:

Select forUpdate Tab1 exists join Tab2 where Tab1.id = Tab2.id and Tab2.Group=’BBB’

{ Tab1.doDelete()}

 

Why delete_from … is wrong in CIL in BatchServer?

*This post is locked for comments

  • Ireneusz Smaczny Profile Picture
    Ireneusz Smaczny 1,535 on at
    RE: Locking /deadlock in Ax2012 (delete_from in BatchServer

    I changed flag 1224 (DBCC TRACEON (1224, -1);) but nothing changed.

    I added try {} catch (Exception::DeadLock) but I still have deadlock in the same select :-(

    Any help?

  • Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: Locking /deadlock in Ax2012 (delete_from in BatchServer

    Also check that you have an index by id and Group fields and add

    catch (Exception:Deadlock)
    {
       retry;
    }


    to handle it.

  • nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Locking /deadlock in Ax2012 (delete_from in BatchServer

    Maybe a lock escalation occurs. You can use trace flag 1224 to relax the lock escalation rules in SQL Server.

    blogs.msdn.microsoft.com/.../sql-server-lock-escalation-and-blocking

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans