Lock Table

redStriperedStripe Member Posts: 83
edited 2006-09-06 in Navision Attain
Hello,
I would like to lock a specific table during the runtime of a function.
If there is set a flag, this lock should be reset.
I tried 2 ways:

1. Locktable
Loop that check if the parameter ist set
if yes, reset the lock

2. I made a little form and in the onTimer Trigger i write a dummy record
to the table and after that I delete it. So Navision should lock this
table by itself.

To test both ways I tried so write new data to the locked table - and it
worked!?! But why??? I locked that table ... why I can write to it?
It should be permitted.

regards,
redStripe

Comments

  • nunomaianunomaia Member Posts: 1,153
    The form with timer and the lock were running in the same client?
    Nuno Maia

    Freelance Dynamics AX
    Blog : http://axnmaia.wordpress.com/
  • redStriperedStripe Member Posts: 83
    I tried both.
    I can write data to the table in the client where the form runs, but also
    from an other client I can write to the table.
  • bbrownbbrown Member Posts: 3,268
    Which database are you using (Native or SQL)?
    There are no bugs - only undocumented features.
  • redStriperedStripe Member Posts: 83
    sorry I forgot to say ... it is a Native DB
  • bbrownbbrown Member Posts: 3,268
    How are you calling the LockTable? Remember that the lock will only last to the end of the current transaction. Put something like a CONFIRM statement that will hold the transaction open.
    There are no bugs - only undocumented features.
  • redStriperedStripe Member Posts: 83
    I do it this way ...
    //blocking the table
    recTable.Locktable(true);
    
    repeat
      //stop and wait
    until parameter = true
    
    //unblocking the table
    recTable.reset;
    

    as long as the parameter = false the the table should be locked.
    But I can insert a new row without any problem ... why???
  • krikikriki Member, Moderator Posts: 9,112
    Important : Navision buffers its writes to the DB on the client. Once the buffer is full or an immediate response is required from the server, it is send to the DB.
    If you are debugging, this buffering does not happen.
    So the LOCKTABLE itself does not always lock the table immediately. If you want to do that, you should put a "IF FINDFIRST THEN ;" [or FIND('-') ] after it.
    This last piece of code sends the "LOCKTABLE"-request to the DB and the table will be locked.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • redStriperedStripe Member Posts: 83
    i put a find('-') now after the locktable ... but I get the same result nothing
    changed :(
    Are there maybe other ways to block a table?
  • krikikriki Member, Moderator Posts: 9,112
    Try this:
    recTheTable.LOCKTABLE;
    IF recTheTable.FIND('-') THEN ;
    IF CONFIRM('The table should be locked now',FALSE) THEN ;
    COMMIT; // a RESET doesn't free the table. A COMMIT does.
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.