Autoincrement Error?

Dakkon
Member Posts: 192
I have a table I created in Navision SQL 4.0 SP2. This table has a field called ID that is the primary key (integer) and I recently changed it to an autoinrement for my testing. The code I'm using to insert records doesn't assign the number as you can see below:
StatusWin.OPEN('Inserting test records\Record #1#############'); FOR I := 50000 TO 100000 DO BEGIN StatusWin.UPDATE(1,I); Rec.INIT; //Rec.ID := I; Rec.RandomCode := 'AHJYEFASEJ'; Rec.RandomText := 'sdf;alkjewrkewj;we'; RANDOMIZE(); Rec.SomeNumber := 100 * 100 / 5 + 200 + RANDOM(1000); Rec.DateTime := CURRENTDATETIME(); Rec.INSERT(TRUE); END; StatusWin.CLOSE;For some reason every time I try to run this code I'll get an error of:
where x = the next available number. When this happens it never actually inserts any records, however, it does increase the autoincrement seed number. Anyone know why this would happen?The Test Entry already exists.
Identification fields and values:
ID='x'
Thad Ryker
I traded my sanity for a railgun
I traded my sanity for a railgun

0
Comments
-
If you changed it to AutoIncrement in SQL, that does not work for Navision. You will need to put in Navision code to find the last entry and increment the value, and assign that value to the new record.Kristopher Webb
Microsoft Dynamics NAV Developer0 -
right, Navision doesnt see the SQL properties from SQL Server Tabel you have set in SQL Manager (or with other tools). also navision doesnt see Tabels which you have created with an 3-rd party program (like Enterprise manager). The reason is: This Tables ar not included in the Object Table.
regardsDo you make it right, it works too!0 -
Actually I changed it in the Navision properties for the field. Nothing was changed from anywhere other than inside Navision.Thad Ryker
I traded my sanity for a railgun0 -
That property only works in sql.0
-
We're using SQL. Navision SQL 4.0 SP2. Incidentally this error only happens when I insert via code. If you manually insert records into the table the autoincrement works as one would expect it to.Thad Ryker
I traded my sanity for a railgun0 -
Do not forget that INIT don't clear fields of primary key! To be able to use autoincrement, you need to assign 0 to the PK field before you do INSERT.1
-
You rock dear sir!! Initializing with 0 does indeed solve the issue.Thad Ryker
I traded my sanity for a railgun0 -
-
Nifty! I didn't even remember that property was there.Kristopher Webb
Microsoft Dynamics NAV Developer0 -
It wasn't. It is new property from 4.00 (or 3.70? I do not know now).0
-
One issue with that property is that if you are on sql and you try to populate the field, you'll a wierd error if you are not a dbowner. I think there are a couple of threads about it.0
-
It is not weird and it is what we are solving (it is solved...) there... :-)
It is not weird if you take it from SQL point of view. This field has connected some identity (step, seed, etc.). This is some counter which is automatically increased when new record is inserted. When you insert record with this field filled in with some value, to prevent inserting same value through autoincrement, the counter must be set to this new manually inserted value to continue in counting. Bud because this identity is part of metadata of the table, you need to have enough rights to do that.0 -
Thanks guys, this was driving me nuts!
========================
Do not forget that INIT don't clear fields of primary key! To be able to use autoincrement, you need to assign 0 to the PK field before you do INSERT.
_________________
Kamil SacekProfessional Navision Developer0 -
=D> Thxx \:D/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
- 320 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