Trapping key violation errors 
Author Message
 Trapping key violation errors

I have a routine that does a series of inserts into a table that has a
primary key.  It's possible that data coming in could contain duplicate
data, of course, and when this happens the key is violated and the record
is not added.

I wanted to trap this and send the offending record to a log file or wait
window or something, but when I put in the ON ERROR SUSPEND just to take
a look at the ERROR() value at that point, it shows 0. Now, the MESSAGE()
string is "Uniqueness of index PK_UID_PID is violated."  But when I put
in the error handling routine, I obviously want to test the ERROR() value
to determine the action.  Why isn't there a value here?  How should I go
about this?

------
Michael



Mon, 05 Sep 2005 03:25:41 GMT  
 Trapping key violation errors
Hi Michael!

Take a look at AERROR()

The fifth element of that error array will
contain 1-3 if a trigger failed.

But ERROR() should give you 1539 then
or in case of the violation of the uniqueness of an index it's 1884.
Hmmm....

Maybe its because of the suspend?

try
ON ERROR DO SET STEP ON

or SET ASSERT ON and use
ON ERROR DO ASSERT .F.

But if you want to log that record you should have an
errorhandler that resumes after logging the failed INSERT...

Quote:
> I wanted to trap this and send the offending record to a log file or wait
> window or something, but when I put in the ON ERROR SUSPEND just to take
> a look at the ERROR() value at that point, it shows 0. Now, the MESSAGE()
> string is "Uniqueness of index PK_UID_PID is violated."  But when I put
> in the error handling routine, I obviously want to test the ERROR() value
> to determine the action.  Why isn't there a value here?  How should I go
> about this?

Bye, Olaf.


Wed, 07 Sep 2005 22:48:06 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Deleted record causing primary key violation

2. Error trapping within my ON ERROR routine

3. Trapping key labels.

4. Trapping the escape key

5. help trapping ESC key in sticky menus

6. Help Needed With <Esc> Key Trapping

7. Trapping the Esc key

8. trapping for key strokes...

9. Need help trapping F and Ctrl keys, Removing Fox tool bars programmatically

10. Trapping the <ESC> key during popups

11. Trapping and using function keys on forms

12. Need help trapping F and Ctrl keys, Removing Fox tool bars programmatically

 

 
Powered by phpBB® Forum Software