Strange Locking Issue
megawavez
Member Posts: 133
Hi,
We are doing something like this on a table:
TableRec.SETRANGE("Field1", 'XXXX');
If TableRec.FINDSET() THEN REPEAT
TableRec.DELETE(TRUE);
UNTIL Table.NEXT() = 0;
This set of code looks to be doing something like a table lock - If I end up running this routine at the same time on another instance of navision classic (6.0) with a different range (i.e. 'YYYY' instead of 'XXXX'), the second instance of navision will end up with a "Another User Has Locked TableRec". I think this is related to SERIALIZATION ?
Thanks for any help.
Mega
We are doing something like this on a table:
TableRec.SETRANGE("Field1", 'XXXX');
If TableRec.FINDSET() THEN REPEAT
TableRec.DELETE(TRUE);
UNTIL Table.NEXT() = 0;
This set of code looks to be doing something like a table lock - If I end up running this routine at the same time on another instance of navision classic (6.0) with a different range (i.e. 'YYYY' instead of 'XXXX'), the second instance of navision will end up with a "Another User Has Locked TableRec". I think this is related to SERIALIZATION ?
Thanks for any help.
Mega
0
Comments
-
It's normal if you don't use setcurrentkey("Field1"). After locktable or any modification/deletion/insertion in table Navision use updatlock hint to reading data from SQL Server. So, if you use wrong key - lot of records may be blocked.
Try to rewrite code with setcurrentkey("Field1") or use temporary table.Looking for part-time work.
Nav, T-SQL.0 -
rmv_RU wrote:It's normal if you don't use setcurrentkey("Field1"). After locktable or any modification/deletion/insertion in table Navision use updatlock hint to reading data from SQL Server. So, if you use wrong key - lot of records may be blocked.
Try to rewrite code with setcurrentkey("Field1") or use temporary table.
Well, that fixed it !
I had been told that sql picks the keys to use for navision operations automatically, but I guess that's really not the case.
Thanks,
Mega0 -
-
The advice has been correct for a while long time ago.
I remember 5 years ago each NAV build had different best practices.
Now (last years) they fixed it back to SQL prefering the SETCURRENTKEY to be there, it behaves more like the old Native database.0 -
Mark Brummel wrote:The advice has been correct for a while long time ago.
I remember 5 years ago each NAV build had different best practices.
Now (last years) they fixed it back to SQL prefering the SETCURRENTKEY to be there, it behaves more like the old Native database.
This is a pretty significant change, so let's hope no changes in the future.0 -
so, by only adding setcurrentkey("Field1") this is solved.
And NAV doesn't use "Field1" as default if not specified in code?0 -
If you do not specify the setcurrentkey the primairy key will be used for the ORDER BY statement.0
-
ok
but why did it solve his problem to add the primary key in the setcurrentkey() ? 0 -
SQL Server analyses the query that comes in and determines the best key to use.
If you do for example
SELECT * FROM CUSTOMER WHERE ADDRESS = 'XX' ORDER BY NO
or
SELECT * FROM CUSTOMER WHERE ADDRESS = 'XX' ORDER BY ADDRESS
SQL Server is more likely to use the index in the second example.0 -
That's clear.
But why did it help the TS to add setcurrentkey() ? That's automatically the default? :-k0 -
I don't think that in this case it was the default. Must have been something else.0
-
@megawavez, could you provide more info?
When we do an update for records, we expect the primary key to be used.
As a result we do not use setcurrentkey(..with primary field...) as it's already used by default.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
- 610 NAV Courses, Exams & Certification
- 1.9K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 251 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
