Another user has modified the record...

ta5
ta5 Member Posts: 1,164
Hi
I have a strange error with two processes running concurrently.

This is an example.
    Table x with 1 Record Codeunit A does something which takes 10 seconds, to reproduce it it could be just sleep(10000) Codeunit B modifies the record in Table x while Codeunit A is working/sleeping Codunit A is started, then Codeunit B from another Workstation Codeunit B takes only a few miliseconds and finishes then After Codeunit A has finished the first part, there is a get on the record in Table x and then a modification On modification I'm getting the Error "Another user has modified the record for x..."

I could use selectlatestversion or a commit in Codeunit A, but I actually dont understand where the problem is. The get in Codeunit A has been sent after Codeunit B has finished :?

Thanks
Thomas

Comments

  • nunomaia
    nunomaia Member Posts: 1,153
    Are you using LOCKTABLE ?
    Nuno Maia

    Freelance Dynamics AX
    Blog : http://axnmaia.wordpress.com/
  • ta5
    ta5 Member Posts: 1,164
    No, I don't.
    Acutally I could use it but I dont understand why the problem occurs.
    The codeunit who changes the table has finished and the get in the actual codeunit is excecuted after the mentioned codeunit has finished.

    Any ideas?

    Thanks
    Thomas
  • nunomaia
    nunomaia Member Posts: 1,153
    Without seeing the code it’s difficult to see the error, but using lock table should solve your problem.
    Nuno Maia

    Freelance Dynamics AX
    Blog : http://axnmaia.wordpress.com/
  • ssingla
    ssingla Member Posts: 2,973
    I am also experiencing the same problem.
    The code is running between couple of tables and several functions of codeunit. Two variables are using one table and are modified at different point of time in different functions.
    The Hierarcy is something like this :
    SalesHeaderVar1 is initiated and then SalesHeaderVar2 is initiated. SalesHeaderVar2 is modified and then SalesHeaderVar1 is modified.

    The error appears when SalesHeaderVar1 is modified. Is there anyway to solve this.
    CA Sandeep Singla
    http://ssdynamics.co.in
  • ta5
    ta5 Member Posts: 1,164
    This is Codeunit a
    Window.OPEN('wait 10');
    SLEEP(10000);
    Window.CLOSE;
    TestTable.GET;
    TestTable.description := FORMAT(TIME) + '   1';
    TestTable.MODIFY;
    

    This is Codeunit b
    TestTable.GET;
    TestTable.description := FORMAT(TIME) + '   2';
    TestTable.MODIFY;
    


    Codeunit b is started while Codeunit a is waiting (sleep). I know that I can use locktable or commit in Codeunit a but I wonder why I get an error at all.

    Regards
    Thomas
  • Mbad
    Mbad Member Posts: 344
    I have seen a few problems with threads and NAV, try using yield.
  • nunomaia
    nunomaia Member Posts: 1,153
    Yes, that kind of coding will give error.

    Don’t forget that the concept of optimistically concurrency is violated there, so will give error in modify.

    You can’t change a record that was previously read and try to change it later. Records have timestamps and are different after modify.
    Nuno Maia

    Freelance Dynamics AX
    Blog : http://axnmaia.wordpress.com/
  • ta5
    ta5 Member Posts: 1,164
    nunomaia wrote:
    You can’t change a record that was previously read and try to change it later. Records have timestamps and are different after modify.

    This is exactly, what I dont understand. Imho the GET on the table is executed a long time after the codeunit b has finished. :?
  • ta5
    ta5 Member Posts: 1,164
    Anyone more info on that?
    Thanks in advance
    Thomas