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