Hello.
Using VBScript, after every execution of a Stored Procedure, I check the
Error object. Some Stored Procedures return a collection of errors e.g.
when trying to insert a duplicate row.
In this case, I only want the last error in the collection which is my
user defined error (created with a RAISERROR). I know than
conn.Errors.Count holds the number of errors in the collection.
I tried to pick up the last error by using the following code but did not
get the desired result:
Dim userError
userError = conn.Errors(conn.Errors.count).Description
Using the following code I got the desired results but it just seems so
clumsy:
Dim iCnt
Dim errLoop
If conn.Errors.Count > 0 Then
'Only pick up the last error message - the user generated one
iCnt = 0
For Each errLoop in conn.Errors
iCnt = iCnt + 1
If iCnt = conn.Errors.Count Then
ErrorRoutine.TrapError = errLoop.Description
End If
Next
End If