Error in Data locking and concurrency using Native DB server

m.pacanam.pacana Member Posts: 75
Do you have any idea on how to avoid this error?

"Another user has modified the record for <table name> <primary key> ' pk record value' after you retrieved it from the database"

When I'm using SQL Server, i never come up with this error when executing my code. But when I run it using Navision Database Server, I end up having this error. Do you have any possible resolution on this? [-o<

Thanks!

Comments

  • kinekine Member Posts: 12,562
    1) This can be mistake in the C/AL code. Because it is not problem on MS SQL, it seems, that somewhere is MODIFY called without modifing anything (on MS SQL will not be the record changed - but I am not sure) and after that is some other MODIFY on another record variable...

    2) If it is problem only sometime and when there are more users on the DB, it is common, if the tables are not locked. (for example two users are editing same order header etc.)

    You need to analyze this from this point:
    a) When it is happen
    b) If allways in same process, independent if there are more users, it is problem of C/AL code. Than you can use Client Monitor to catch the points where is the table (record) modified and analyze the code
    c) If it is problem only sometime, if there are another users working with the table, it is common...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • krikikriki Member, Moderator Posts: 9,118
    It is also possible if no other users are working in the DB, but it is a problem of the programming. I give an example on how it can happen:

    You run the code below here, you take a record and it has version 1.
    You launch a function that takes THE SAME RECORD WITH THE SAME VERSION (=version 1).
    You change the record in the function and save it. When saving, Navision controls if the version in the variable is the same as the one in the DB and in this case it is the same, saves it AND CHANGES THE VERSION (=>version 2!
    Now in the calling part you change the same record that still has version 1!
    Save it, Navision checks and sees that the variable is version 1 and the DB is version 2=> ERROR!
    You should do a recMyRecord.FIND('='); after the function to get version 2 of the record.

    recMyRecord.GET(1);
    FunctionDoSomething();
    recMyRecord."Some Field" := "Some Value";
    recMyRecord.MODIFY(FALSE); // or MODIFY(TRUE);
    
    FUNCTION FunctionDoSomething();
      recMyRecord.GET(1);
      recMyRecord."Some Field" := "Some Value";
      recMyRecord.MODIFY(FALSE); // or MODIFY(TRUE);
    END FUNCTION;
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • DenSterDenSter Member Posts: 8,307
    And you can even prevent that situation altogether by sending the record variable into the function by reference, so that the calling code knows about the changes in the function. That way you don't have to make another roundtrip to the server to get 'refreshed' data.
  • m.pacanam.pacana Member Posts: 75
    thanks for the help guys.. \:D/ Actually I have called the MODIFY function twice in a function. See the following code snippet:

    Assuming Table1 and Table2 are record variables of NAVTABLE; the GUIDs have different values.

    IF Table1.GET(sampleGUID) THEN BEGIN
    Table1.Field1 := TRUE;
    Table1.MODIFY;

    IF sampleGUID2 <> sampleGUID THEN BEGIN
    CLEAR(Table2);
    IF Table2.GET(sampleGUID2) THEN BEGIN

    Table2.Column2 := 'value2';
    Table2.Column3 := 'value';

    TrimOtherRecordValues(); //only trimming records but not saving

    Table2.MODIFY;
    END;
    END;
    END;

    When the table2.Modify was invoked, the error occurs. In this way, I want to modify two records in one table. Do you know how to resolve this?

    By the way, what does recMyRecord.FIND('=') do?
  • m.pacanam.pacana Member Posts: 75
    DenSter wrote:
    And you can even prevent that situation altogether by sending the record variable into the function by reference, so that the calling code knows about the changes in the function. That way you don't have to make another roundtrip to the server to get 'refreshed' data.

    I have used this in my other functions but I guess i dont need this in this given scenario. thanks :)
  • krikikriki Member, Moderator Posts: 9,118
    m.pacana wrote:
    By the way, what does recMyRecord.FIND('=') do?
    Use the help function of Navision. :-)

    FIND('=') is like GET,but the primary-key-fields must have been filled up in the record.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • kinekine Member Posts: 12,562
    kriki wrote:
    FIND('=') is like GET,but the primary-key-fields must have been filled up in the record.

    And the filters are used (get is ignoring filters)... 8)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • krikikriki Member, Moderator Posts: 9,118
    kine wrote:
    kriki wrote:
    FIND('=') is like GET,but the primary-key-fields must have been filled up in the record.

    And the filters are used (get is ignoring filters)... 8)
    Right, forgot that particularity. Thanx kine
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • m.pacanam.pacana Member Posts: 75
    Ok Thanks.. I'll try this then. \:D/
  • DenSterDenSter Member Posts: 8,307
    IF sampleGUID and sampleGUID2 are different then you should never get that error. The message comes up when two variables store the same records, and they both MODIFY. The first one goes through without a problem, and the second one will give you the error saying 'another user has modified the record'.
Sign In or Register to comment.