WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

ADO DAO
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

ADO Error Object

 Keywords: ADO Error Errors ADODB Connection errorhandling

ADO errors are reported to your script as run-time errors. You can use errorhandling to trap and handle them. (ErrorMode or IntControl 73)

You can access error information from the error object.

For Example:

#DefineFunction udfErrorHandler(wberrorarray)
   lasterr = wberrorarray[0]
   handlerline = wberrorarray[1]
   textstring = wberrorarray[5]
   linenumber = wberrorarray[8]
   errstr = StrCat("Number: ",lasterr,@LF,"String: ",textstring,@LF,"Line (",linenumber,"): '",handlerline,"'")
   Message("WIL Error Information",errstr)
   Return 1 ;Re-arm error handler
#EndFunction

IntControl(73,3,1,'udfErrorHandler',0); Defines and sets the error handler UDF.

objConn = CreateObject("ADODB.Connection")
objError = objConn.Errors
ret = objConn.Open("nothing")  ; !!! Intentionally trigger an error. !!!

If objError.Count > 0
 ;list Errors collection and display properties of each Error object.
 ForEach errLoop In objConn.Errors
      strError = "Error #" : errLoop.Number : @CRLF :"   " : errLoop.Description : @CRLF :"   (Source: " : errLoop.Source : ")" : @CRLF :"   (SQL State: " : errLoop.SQLState : ")" : @CRLF :"   (NativeError: " : errLoop.NativeError : ")" : @CRLF
      If errLoop.HelpFile == ""
         strError = strError :"   No Help file available"
      Else
         strError = strError :"   (HelpFile: " : errLoop.HelpFile : ")" : @CRLF :"   (HelpContext: " : errLoop.HelpContext : ")"
      EndIf
      Pause('ADODB error', strError)
  Next
EndIf
Exit


objConn = CreateObject("ADODB.Connection")
ErrorMode(@OFF)
objConn.Open("nothing")  ; !!! Intentionally trigger an error. !!!
ErrorMode(@CANCEL)
If objConn.Errors.Count > 0
 ;list Errors collection and display properties of each Error object.
 ForEach errLoop In objConn.Errors
      strError = "Error #" : errLoop.Number : @CRLF :"   " : errLoop.Description : @CRLF :"   (Source: " : errLoop.Source : ")" : @CRLF :"   (SQL State: " : errLoop.SQLState : ")" : @CRLF :"   (NativeError: " : errLoop.NativeError : ")" : @CRLF
      If errLoop.HelpFile == ""
         strError = strError :"   No Help file available"
      Else
         strError = strError :"   (HelpFile: " : errLoop.HelpFile : ")" : @CRLF :"   (HelpContext: " : errLoop.HelpContext : ")"
      EndIf
      Pause('error', strError)
  Next
EndIf

Article ID:   W18032
Filename:   ADO Error Object.txt
File Created: 2009:07:23:08:57:58
Last Updated: 2009:07:23:08:57:58