Incredibly strange error from COUNT function
Dakkon
Member Posts: 192
I'm running into a bizarre situation where calling COUNT on a table is generating a very unexpected error. The error is as follows:
As you can see, this is the typical error that you would get when attempting to insert a duplicate key entry into a table. The error is raised from the following code line:
What makes this yet even stranger is that prior to this code (in my test case) I have called DELETEALL before inserting a single line. Obviously if all the records are deleted and one entry is then inserted, there should be no key collision. I have never in my life seen Navision generate a "line already exists" error from a call to the COUNT function. I'm assuming this must be a bug in the new RTC nav engine. Has anyone else seen this happen? Does anyone know what is going on here?
The Dynamic Move Line already exists. Identification fields and values: ...
As you can see, this is the typical error that you would get when attempting to insert a duplicate key entry into a table. The error is raised from the following code line:
IF DynamicMoveLine.COUNT > 1 THEN
What makes this yet even stranger is that prior to this code (in my test case) I have called DELETEALL before inserting a single line. Obviously if all the records are deleted and one entry is then inserted, there should be no key collision. I have never in my life seen Navision generate a "line already exists" error from a call to the COUNT function. I'm assuming this must be a bug in the new RTC nav engine. Has anyone else seen this happen? Does anyone know what is going on here?
Thad Ryker
I traded my sanity for a railgun
I traded my sanity for a railgun
0
Best Answer
-
This is caused by the buffered insert functionality which basically delays INSERTs and then add them all in one go. The code before this statement is adding the ducplicate record but it's only when this statement is run that NAV decides to actually do the bulk insert and you get the error.
In later versions of NAV you can disable this bulk/delayed insert functionality, there is an option called "Enable Buffered Insert" which you can untick in the Administration tool to stop this delayed behaviour - you'll then see exactly where the error is coming from (i.e. the INSERT statement)5
Answers
-
This is caused by the buffered insert functionality which basically delays INSERTs and then add them all in one go. The code before this statement is adding the ducplicate record but it's only when this statement is run that NAV decides to actually do the bulk insert and you get the error.
In later versions of NAV you can disable this bulk/delayed insert functionality, there is an option called "Enable Buffered Insert" which you can untick in the Administration tool to stop this delayed behaviour - you'll then see exactly where the error is coming from (i.e. the INSERT statement)5 -
Thank you Kishorm, the explanation is much appreciated. I'm still puzzled as to how it is encountering a duplicate record on insert (given that I'm calling DELETEALL prior), but that is a separate issue.Thad Ryker
I traded my sanity for a railgun
0 -
No problem!
After your DELETEALL you must be INSERTing some records (otherwise there'd be no point doing a COUNT?) so it's during these INSERTs that you are adding 2 records with the same key.0 -
Actually it turned out to be an issue in the filters applied before the DELETEALL. I was actually only inserting one record because it was a test scenario, the COUNT check is there for production situations, but I was simply trying to test a specific scenario. The issue was that the incorrect filters resulted in not all of the existing records being deleted that I had expected.Thad Ryker
I traded my sanity for a railgun
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K 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
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 323 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions