Friday, August 21, 2020

NAV/BC - Record is locked by another user - What causes locks and how to avoid them


  • The purpose of locking is to maintain data integrity during the execution of a function, and to minimize blocking (where two functions try to change the same data at the same time)
  • What causes locking?
    • Automatic
      • Whenever a table is being written to (Insert, modify delete), it is automatically locked
        • Depending on the filter, an entire range will be locked to ensure the filter returns accurate data (SETFILTER may lock a range, GET locks a single record)
        • Records before and after a specific range or record will also get locked
        • Using Findlast locks the last record and prevents insertion of new records
      • During a large read or application of filters that return many records 
    • Intentional
      • Locktable function will lock any records/tables accessed after the locktable function is called until the function is finished
  • What removes locking?
    • After a Commit function
    • After a CAL module is exited
    • After a read function completes
  • Guidelines to prevent locking scenarios
    • Do not leave long write commands in loop limbo, Commit often enough to prevent locking.
    • Use Setcurrentkey to change sorting options so that you are not locking records close to records users may be actively using
    • Define your own locks to prevent the system from locking in an improper order

No comments:

Post a Comment