Solved

Handling an ODBC - CALL FAILED Error

Posted on 2000-05-08
5
805 Views
Last Modified: 2008-03-06
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
Comment
Question by:danlevans
  • 3
  • 2
5 Comments
 
LVL 18

Expert Comment

by:mdougan
Comment Utility
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
 
LVL 18

Expert Comment

by:mdougan
Comment Utility
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
 
LVL 2

Author Comment

by:danlevans
Comment Utility
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
 
LVL 18

Accepted Solution

by:
mdougan earned 200 total points
Comment Utility
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
 
LVL 2

Author Comment

by:danlevans
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now