insert sql error

geronimo
Member Posts: 90
Is there a way to catch an sql insert error in nav code from outside the function?
a little example (just to make things clear):
i have 2 tables
both have this setup
1 code code 10
2 description text 30
All i do is copy the data over from one table to the other like this:
However when i run the codeunit the second time i get this error
Microsoft Dynamics NAV Classic
Tabel testtable2 is reeds aanwezig.
Velden en waarden:
code='01'
OK
Which is expected as it should occur. I know i can write an "if" around it to catch the error. But i dont want to go around writing if's all over the database to then throw my own error that i can log with the getlasterrortext function.
So i'd like to know if there is a way to catch this without having to modify all over the place, as mentioned before the example above is merely for posting an example.
a little example (just to make things clear):
i have 2 tables
both have this setup
1 code code 10
2 description text 30
All i do is copy the data over from one table to the other like this:
Fct_MoveData() LRec_1.RESET; IF LRec_1.FINDSET(FALSE,FALSE) THEN BEGIN REPEAT LRec_2.RESET; LRec_2.TRANSFERFIELDS(LRec_1); LRec_2.INSERT(TRUE); UNTIL LRec_1.NEXT = 0; END;
However when i run the codeunit the second time i get this error
Microsoft Dynamics NAV Classic
Tabel testtable2 is reeds aanwezig.
Velden en waarden:
code='01'
OK
Which is expected as it should occur. I know i can write an "if" around it to catch the error. But i dont want to go around writing if's all over the database to then throw my own error that i can log with the getlasterrortext function.
So i'd like to know if there is a way to catch this without having to modify all over the place, as mentioned before the example above is merely for posting an example.
0
Comments
-
yes, you create a CU that calls this function on OnRun trigger.
MyCU5000
onRun
Fct_MoveData();
Then you create another CU and call it
if MyCU5000.run then begin
message('success');
end else begin
logtheerror(getlasterrortext);
clearlasterrortext;
end;0 -
ara3n wrote:yes, you create a CU that calls this function on OnRun trigger.
MyCU5000
onRun
Fct_MoveData();
Then you create another CU and call it
if MyCU5000.run then begin
message('success');
end else begin
logtheerror(getlasterrortext);
clearlasterrortext;
end;
for example:
2 codeunits:
60000:Documentation() OnRun() IF COdeunit60001.RUN THEN; //IF CODEUNIT.RUN(60001) THEN; MESSAGE('test: %1',GETLASTERRORTEXT);
Codeunit 60001Documentation() OnRun() Fct_MoveData() LRec_1.RESET; IF LRec_1.FINDSET(FALSE,FALSE) THEN BEGIN REPEAT LRec_2.RESET; LRec_2.TRANSFERFIELDS(LRec_1); LRec_2.INSERT; UNTIL LRec_1.NEXT = 0; END;
0 -
Are you getting a sql error or NAV Error? and you are not getting the message 'test: The error?'
Do you have any code on sql trigger?
I have seen this before where an insert error would stop the execution of the calling CU.
I suggest to report it to MS if you can replicate it in Cronus. probably newest executable.0 -
ara3n wrote:Are you getting a sql error or NAV Error? and you are not getting the message 'test: The error?'
Do you have any code on sql trigger?
I have seen this before where an insert error would stop the execution of the calling CU.
I suggest to report it to MS if you can replicate it in Cronus. probably newest executable.
no code on sql trigger.
I'm not getting the message. It stops at the insert when i enable the debugger.
Will have a look in cronus and come back when i have the results
Thanks so far already0
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