Solved

Handling an ODBC - CALL FAILED Error

Posted on 2000-05-08
5
817 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
ID: 2789707
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
ID: 2789720
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
ID: 2800245
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
ID: 2803104
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
ID: 2804618
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

816 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

10 Experts available now in Live!

Get 1:1 Help Now