• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 850
  • Last Modified:

Handling an ODBC - CALL FAILED Error

I have a program monitoring data on an AS400 using ODBC. I use ADODC objects bound to Data Grids. I want this program to run continously. Occasionally I will get an ODBC - CALL FAILED message -214767259 (80004005) which requires a response of OK before crashing and burning. I would like to trap this error so I could kill and restart the program or do a delay and retry or both. What code could I use and where would I put it to trap the error before the message box requiring the OK is issued? I know I could extend the timeouts but I would prefer to restart.

dan
0
danlevans
Asked:
danlevans
  • 3
  • 2
1 Solution
 
mdouganCommented:
The message box that pops up is probably VB's built-in error handler.  If you wish to handle the error yourself, you need to add an error handler to any Sub or Function that might possibly generate an error (to be safe, I put one in every routine).  Here is a sample of a routine you could use:

Private Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)


Private Sub DoDatabaseLookup()
Dim RetryCount as long
On Error go to ErrRtn


TryAgain:
' your code goes here


ExitRtn:
Exit Sub

ErrRtn:
If Err.Number = -214767259 then
   if RetryCount < 6 then
      Retry Count = RetryCount + 1
      Sleep(10000)
      Resume TryAgain
   Else
      Printer.Print "Program stalled for over 1 minute"
      Printer.EndDoc
      End
   End if
Else
   Printer.Print Err.Number & " - " & Err.Description
   Printer.EndDoc
   Resume ExitRtn
End if

End Sub        

If you get the same error number for all different database errors, then alternatively you can search the Error Description for specific text:

ErrRtn:
If InStr(1, Err.Description, "CALL FAILED", vbTextCompare) > 0 then
    if RetryCount < 6 then
0
 
mdouganCommented:
By the way, it looks like EE is not handling the the double-quotes correctly.  Most of the things that have a questionmark above are supposed to be a double-quotes (some are supposed to be amperstands), and the other comparison operators are supposed to be the greater than sign.
0
 
danlevansAuthor Commented:
mdougan,

I tried your suggestion and it does not trap the error.

Where would you put code to trap errors in the ADODC (not ADODB) object that is bound to a data grid on the form?

I have put error traps in all my code associated with this form.

dan
0
 
mdouganCommented:
OK, my mistake, I need to read the question more carefully.  When you have bound controls, and data controls, the data control has an Error Event that will fire if there is a problem.  Look for the Error Event and you'll see a parm that the system passes called something like fCancelDisplay.  The help file says set this to False to continue, True to display the error, but that sounds backwards.  Just display the value of fCancelDisplay, and set it to the opposite, as the default value will cause the data control to display the error and then crash the program.
0
 
danlevansAuthor Commented:
mdougan,

Exactly what I needed! I had played with the error method but missed the fCancelDisplay (it was off my screen) I will learn to look harder. Thanks again

dan
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now