Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 9069

Re: Could not commit transaction: Deadlock(-2038) detected during transaction

$
0
0

Hi Dilip,

 

Below a quote from the SDK Help file

 

SAP Business One SDK 9.0

 

Avoiding Database Deadlocks

In a landscape with more than one client, it is possible that database deadlocks will occur. In most cases, an add-on can handle potential deadlocks simply by retrying the operation.

When handling deadlocks, the following rules apply:

  • Any variable read from the API in a transaction can no longer be used because the data is already dirty.
  • Keep retrying until the data is added.

The following is an example of handling potential deadlocks:

const long DEADLOCK_ERR_CODE = -2038;

long DeadlockTryTime = 100;

long i =0;

bool retCode = false;

for (i=0; i<DeadlockTryTime; i++)

{

    try

    {

        retCode = DoOperations(); //start end transaction are contained within the function.

        if (returnCode == success)

        {

            break;

        }

        else

        {

            // basic error handling

        }

    }

    catch (System.Runtime.InteropServices.COMException ex)

    {

        if (ex.ErrorCode == DEADLOCK_ERR_CODE)

        {

            continue;

        }

        else

        {

            // error handling for non-deadlock ComException exceptions

        }

    }

}

 

if (i == DeadlockTryTime)

{

    // Handle that deadlock retry failed

}

 

Regards

Edy


Viewing all articles
Browse latest Browse all 9069

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>