The question now is how to we "trap" QODBC Insert errors? Well, after any QODBC insert, we will want to put the following lines:
If Err.number <> 0 then TrapError Err.description End If
You will want to put this after all ADO calls that communicate directly with QODBC. This includes ConnectionObject.Open, ConnectionObject.Execute, and RecordsetObject.Open. Now, you may be wondering where the sub TrapError is defined: we're about to do that. Create a file called ErrorHandler.asp and put it in your /include or /scripts directory. In ErrorHandler.asp, we will have the following subs:
TrapError ProcessErrors
Let's look at the code for ErrorHandler.asp:
<% Dim strErrorMessage Dim bolErrors
'Initialize variables strErrorMessage = "" 'The error messages for tech. support bolErrors = False 'Have we found any errors yet?
'Now our two subs sub TrapError(strError) bolErrors = True 'We've found an error!
strErrorMessage = strErrorMessage & strError & ", " end sub
'If there are any errors, this function will show the error sub ProcessErrors() if bolErrors then 'Show the Error
Response.Write "There has been a QODBC error. " & _ "At " & Now & " the following errors occurred on " & _ "the page " & Request.ServerVariables("SCRIPT_NAME") & _ ": " & _ chr(10) & chr(10) & strErrorMessage end if end sub
%>
That's all there is to it! Now, at the top of all your pages that you want to use the error handling routines, you'll need to include ErrorHandler.asp like so:
<!--#include virtual="/include/ErrorHandler.asp"--> |