title: Deadlocking issue in parallel batch processing (Invoice Posting ax 2009)
body: <p>I am getting an error "Cannot select a record in SalesParmSubTable.
  Deadlock, where one or more users have simultaneously locked the whole table or part of it".</p>
  
  <p>I used sql profiler for getting the deadlock trace. Can someone please help to rectify it.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;deadlock-list&gt;
     &lt;deadlock victim="process58d048"&gt;
        &lt;process-list&gt;
           &lt;process id="process58d048" taskpriority="0" logused="5784" waitresource="PAGE: 16:1:16714223" waittime="1587" ownerId="207752233" transactionname="user_transaction" lasttranstarted="2016-05-07T07:58:32.533" XDES="0x52376d950" lockMode="S" schedulerid="4" kpid="10860" status="suspended" spid="159" sbid="0" ecid="0" priority="0" trancount="1" lastbatchstarted="2016-05-07T07:58:32.553" lastbatchcompleted="2016-05-07T07:58:32.553" clientapp="Microsoft Dynamics AX" hostname="*********" hostpid="19816" loginname="************" isolationlevel="read committed (2)" xactid="207752233" currentdb="16" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128056"&gt;
              &lt;executionStack&gt;
                 &lt;frame procname="adhoc" line="1" stmtstart="100" sqlhandle="0x02000000d3d2cf1665ba9e17ee49d6dd9bc2fbf295ad7168"&gt;SELECT A.DEL_SALESID,A.SALESNAME,A.PARMID,A.ORIGSALESID,A.TABLEREFID,A.DEL_ORIGTABLEREFID,A.JOURNALREFTABLEID,A.JOURNALREFRECID,A.SUBID,A.CREATEDDATETIME,A.CREATEDBY,A.RECVERSION,A.RECID FROM SALESPARMSUBTABLE A WHERE ((A.DATAAREAID=@P1) AND (A.PARMID=@P2)) AND NOT EXISTS (SELECT 'x' FROM SALESPARMLINE B WHERE ((B.DATAAREAID=@P3) AND (((B.PARMID=A.PARMID) AND (B.TABLEREFID=A.TABLEREFID)) AND (B.ORIGSALESID=A.ORIGSALESID)))) ORDER BY A.DATAAREAID,A.PARMID,A.DEL_SALESID&lt;/frame&gt;
                 &lt;frame procname="unknown" line="1" sqlhandle="0x000000000000000000000000000000000000000000000000"&gt;unknown&lt;/frame&gt;
              &lt;/executionStack&gt;
              &lt;inputbuf&gt;(@P1 nvarchar(5),@P2 nvarchar(21),@P3 nvarchar(5))SELECT A.DEL_SALESID,A.SALESNAME,A.PARMID,A.ORIGSALESID,A.TABLEREFID,A.DEL_ORIGTABLEREFID,A.JOURNALREFTABLEID,A.JOURNALREFRECID,A.SUBID,A.CREATEDDATETIME,A.CREATEDBY,A.RECVERSION,A.RECID FROM SALESPARMSUBTABLE A WHERE ((A.DATAAREAID=@P1) AND (A.PARMID=@P2)) AND NOT EXISTS (SELECT 'x' FROM SALESPARMLINE B WHERE ((B.DATAAREAID=@P3) AND (((B.PARMID=A.PARMID) AND (B.TABLEREFID=A.TABLEREFID)) AND (B.ORIGSALESID=A.ORIGSALESID)))) ORDER BY A.DATAAREAID,A.PARMID,A.DEL_SALESID&lt;/inputbuf&gt;
           &lt;/process&gt;
           &lt;process id="process572988" taskpriority="0" logused="5800" waitresource="PAGE: 16:1:16714223" waittime="1576" ownerId="207752211" transactionname="user_transaction" lasttranstarted="2016-05-07T07:58:32.530" XDES="0x865e1950" lockMode="S" schedulerid="3" kpid="21628" status="suspended" spid="154" sbid="0" ecid="0" priority="0" trancount="1" lastbatchstarted="2016-05-07T07:58:32.563" lastbatchcompleted="2016-05-07T07:58:32.560" clientapp="Microsoft Dynamics AX" hostname="*********" hostpid="19816" loginname="*********" isolationlevel="read committed (2)" xactid="207752211" currentdb="16" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128056"&gt;
              &lt;executionStack&gt;
                 &lt;frame procname="adhoc" line="1" stmtstart="100" sqlhandle="0x02000000d3d2cf1665ba9e17ee49d6dd9bc2fbf295ad7168"&gt;SELECT A.DEL_SALESID,A.SALESNAME,A.PARMID,A.ORIGSALESID,A.TABLEREFID,A.DEL_ORIGTABLEREFID,A.JOURNALREFTABLEID,A.JOURNALREFRECID,A.SUBID,A.CREATEDDATETIME,A.CREATEDBY,A.RECVERSION,A.RECID FROM SALESPARMSUBTABLE A WHERE ((A.DATAAREAID=@P1) AND (A.PARMID=@P2)) AND NOT EXISTS (SELECT 'x' FROM SALESPARMLINE B WHERE ((B.DATAAREAID=@P3) AND (((B.PARMID=A.PARMID) AND (B.TABLEREFID=A.TABLEREFID)) AND (B.ORIGSALESID=A.ORIGSALESID)))) ORDER BY A.DATAAREAID,A.PARMID,A.DEL_SALESID&lt;/frame&gt;
                 &lt;frame procname="unknown" line="1" sqlhandle="0x000000000000000000000000000000000000000000000000"&gt;unknown&lt;/frame&gt;
              &lt;/executionStack&gt;
              &lt;inputbuf&gt;(@P1 nvarchar(5),@P2 nvarchar(21),@P3 nvarchar(5))SELECT A.DEL_SALESID,A.SALESNAME,A.PARMID,A.ORIGSALESID,A.TABLEREFID,A.DEL_ORIGTABLEREFID,A.JOURNALREFTABLEID,A.JOURNALREFRECID,A.SUBID,A.CREATEDDATETIME,A.CREATEDBY,A.RECVERSION,A.RECID FROM SALESPARMSUBTABLE A WHERE ((A.DATAAREAID=@P1) AND (A.PARMID=@P2)) AND NOT EXISTS (SELECT 'x' FROM SALESPARMLINE B WHERE ((B.DATAAREAID=@P3) AND (((B.PARMID=A.PARMID) AND (B.TABLEREFID=A.TABLEREFID)) AND (B.ORIGSALESID=A.ORIGSALESID)))) ORDER BY A.DATAAREAID,A.PARMID,A.DEL_SALESID&lt;/inputbuf&gt;
           &lt;/process&gt;
        &lt;/process-list&gt;
        &lt;resource-list&gt;
           &lt;pagelock fileid="1" pageid="16714223" dbid="16" objectname="AX2009_****.dbo.SALESPARMLINE" id="lock562bdb480" mode="IX" associatedObjectId="72057635944464384"&gt;
              &lt;owner-list&gt;
                 &lt;owner id="process572988" mode="IX" /&gt;
              &lt;/owner-list&gt;
              &lt;waiter-list&gt;
                 &lt;waiter id="process58d048" mode="S" requestType="convert" /&gt;
              &lt;/waiter-list&gt;
           &lt;/pagelock&gt;
           &lt;pagelock fileid="1" pageid="16714223" dbid="16" objectname="AX2009_****.dbo.SALESPARMLINE" id="lock562bdb480" mode="IX" associatedObjectId="72057635944464384"&gt;
              &lt;owner-list&gt;
                 &lt;owner id="process58d048" mode="IX" /&gt;
              &lt;/owner-list&gt;
              &lt;waiter-list&gt;
                 &lt;waiter id="process572988" mode="S" requestType="convert" /&gt;
              &lt;/waiter-list&gt;
           &lt;/pagelock&gt;
        &lt;/resource-list&gt;
     &lt;/deadlock&gt;
  &lt;/deadlock-list&gt;
  </code></pre>