Tuesday, April 6, 2010

Deadlocks with number sequences

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.

15 comments:

  1. Hello, There's no doubt that your web site may be having browser compatibility problems. Whenever I look at your web site in Safari, it looks fine however, if opening in IE, it has some overlapping issues. I merely wanted to give you a quick heads up! Apart from that, great site!

    My site - Corporate Movers
    My web page: Ohio Moving

    ReplyDelete
  2. I enjoy what you guys are up too. Such clever work and reporting!
    Keep up the fantastic works guys I've added you guys to my blogroll.

    My page ... Movers Dayton

    ReplyDelete
  3. Wonderful, what a webpage it is! This webpage provides valuable information to us, keep it up.



    Also visit my web site: Storage Dayton

    ReplyDelete
  4. Aw, this was an incredibly nice post. Finding the time and actual
    effort to create a really good article… but what can I say…
    I put things off a whole lot and don't manage to get nearly anything done.



    green coffee extract reviews (greencoffeebeanmaxs.org)

    ReplyDelete
  5. Valuable information. Lucky me I discovered your web site by chance, and
    I am surprised why this accident did not came about earlier!
    I bookmarked it.


    Rvtl Anti Aging Solutions

    ReplyDelete
  6. Your style is really unique compared to other folks I've read stuff from. Thanks for posting when you have the opportunity, Guess I will just bookmark this page.


    Lipo slender review

    ReplyDelete
  7. Hello are using Wordpress for your blog platform? I'm new to the blog world but I'm trying
    to get started and create my own. Do you need any coding expertise to make your own blog?
    Any help would be really appreciated!


    Buy mito slim

    ReplyDelete
  8. Very good blog! Do you have any tips for aspiring writers?
    I'm hoping to start my own blog soon but I'm a little lost on
    everything. Would you propose starting with a free platform like Wordpress or go
    for a paid option? There are so many options out there that I'm completely overwhelmed .. Any suggestions? Thanks!

    My page Lean Muscle FOrmula Price

    ReplyDelete
  9. It's very straightforward to find out any topic on net as compared to textbooks, as I found this paragraph at this web site.

    sex drive

    ReplyDelete
  10. Did you know that you can make cash by locking special sections of your blog / site?
    All you need to do is to open an account on Ad Work Media and add their Content Locking widget.

    ReplyDelete