Error in Data locking and concurrency using Native DB server
m.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!
"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!
0
Comments
-
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...0 -
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!0 -
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.0
-
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?0 -
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
0 -
Use the help function of Navision. :-)m.pacana wrote:By the way, what does recMyRecord.FIND('=') do?
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!0 -
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)0 -
Right, forgot that particularity. Thanx kinekine 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)Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
Ok Thanks.. I'll try this then. \:D/0
-
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'.0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 611 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 253 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions

