web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :

Deadlocks with number sequences

Volodymyr Giginiak Profile Picture Volodymyr Giginiak Microsoft Employee
Number sequence cannot be set up and used in the same transaction. If you’ll try to do so you’ll face a deadlock. This happens because of the fact that AX uses separate connection to get next number from a number sequence.

For example, the following code will cause deadlock:
public static void testNumberSequences()
{
    NumberSequenceTable numberSequenceTable;
    NumberSequenceReference numberSequenceReference;

    ttsbegin;
    numberSequenceTable.NumberSequence = 'A';
    numberSequenceTable.Lowest = 1;
    numberSequenceTable.Highest = 99999;
    numberSequenceTable.NextRec = 1;
    numberSequenceTable.Format = '#####';
    numberSequenceTable.Continuous = NoYes::No;
    numberSequenceTable.insert();

    numberSequenceReference.DataTypeId = typeId2ExtendedTypeId(typeid(ItemGroupId));
    numberSequenceReference.NumberSequence = numberSequenceTable.NumberSequence;
    numberSequenceReference.insert();

    NumberSeq::newGetNum(NumberSeqReference::findReference(typeId2ExtendedTypeId(typeid(ItemGroupId)))).num();
    ttscommit;
}

By moving the line with num() call out of tts scope the deadlock will be eliminated.

This was originally posted here.

Comments

*This post is locked for comments