When Do I Need To Use LockTable?

ayashiayashi Member Posts: 78
edited 2006-11-22 in Navision Attain
Hi guys,

If I create a form, with a button, which when this button pushed, it will explode several record into a custom table (inserting).

If I do this in multi-user environment, do I need to lock the custom table ? so that other users won't interfere in the middle of inserting the records ?

Thanks

Comments

  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    If run in a c/side environment Navision will lock the table after the first change to the table and keep the lock active until the transaction is completed.
  • kinekine Member Posts: 12,562
    You need to use tablelock when:

    1) You need to keep correct locking order, but you are accessing the tables in another order...

    2) You need to prevent other users to change or access same record you just read (for example, you read last entry no. and you want to insert some new record later in the process, this will prevent other users to read the last record to do same thing, it will be serialized...)

    3) You want to be sure that you are reading commited data.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • ayashiayashi Member Posts: 78
    talk about commited data .. perhaps my next question a little bit out of topic. If I have this code :

    x := 1
    Repeat
    If x = 5 Then
    Error(Text001)
    Else Begin
    Table.INIT;
    Table."No." := x;
    Table.INSERT;
    End;
    x := x + 1;
    Until x = 10;


    Does this mean when the program raise error message (x=5) and the application stop, the record for x = 1..4 already inserted into the table ?
    or Navision automatically rollback, so that when I open the Table, there won't be any record ?


    Thank Guys
  • kinekine Member Posts: 12,562
    Of course, whole transaction is rolled back. The database will be in same state like after last commit or before you started the process (by pressing button, entering value into field etc.)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • ayashiayashi Member Posts: 78
    thx a lot kine for answering,
    then when do we use commit command ? cause in several navision code, I see some module using 'commit' command
  • ara3nara3n Member Posts: 9,256
    Normally in your code you should not use commit.
    Places where commit make sense is if you
    write your own posting routine.
    write integrations with third party system.
    batch processing orders.
    catching errors in "if CU.run"
    openning a form at the end of transaction.

    dataports sometimes do not commit, and you have to write on postdataport COMMIT
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ayashiayashi Member Posts: 78
    Ok thanks a lot you all for explaining it to me in simple language so that I could understand it :D
  • kinekine Member Posts: 12,562
    You are welcome
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.