private static bool IsDeadlockException(System.Data.Common.DbException e)
{
// Avoid [SqlException (0x80131904): Transaction (Process ID ??) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
// CAUTION: Using e.ErrorCode and testing for HRESULT 0x80131904 will not work!
//... you should use e.Number not e.ErrorCode
var sqlEx = e as System.Data.SqlClient.SqlException;
if (sqlEx == null)
return false;
var sqlExNumber = sqlEx.Number;
var sqlExErrorCode = sqlEx.ErrorCode;
var isDeadLock = sqlExNumber == 1205;
//-- assert
var messageParts = new[]
{
"was deadlocked on lock",
"resources with another process and has been chosen as the deadlock victim. rerun the transaction"
};
var currentMessage = e.Message.ToLower();
var isMessageDeadlock = !messageParts.Where(msgPart => !currentMessage.Contains(msgPart)).Any();
if (sqlEx != null && isMessageDeadlock != isDeadLock)
throw new Exception(String.Concat("Incorrect deadlock analysis",
". Number: ", sqlExNumber,
". ErrorCode: ", sqlExErrorCode,
". Errors.Count: ", sqlEx.Errors.Count,
". Original message: ", e.Message), e);
return isDeadLock;
}
private static Exception SavingExceptionHelper(NodeData data, Exception catchedEx)