Skip to Content

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

I have 5500 items and 450 BOM's. I want to update the price of all the items and then I will update the price of BOM. When I run the add-on, sometimes SAP gets hanged and sometimes I receive the following error -

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Nov 04, 2015 at 12:38 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Nov 03, 2015 at 09:38 AM

    Hi,

    -2038 is a common time-out / deadlock error. This can sometimes happen, especially when you perform a lot of transactions.

    In your addon you should build in an error checking routine that detects the -2038 error, and that simply retries the transaction after a couple of milliseconds.

    Regards,

    Johan

    Add comment
    10|10000 characters needed characters exceeded