Error handler errors

I have an occassional issue with my error handler and not sure why it is happening and was hoping to get some thoughts.

Here is a example of one of the procedures where the error happens

----
Private Function OpenPublisherConnection() As ADODB.Connection
1   On Error GoTo ERROR_HANDLE
2   Set OpenPublisherConnection = New ADODB.Connection
3   If CheckForServer(rsRepConfig!PublisherAddress) Then
4       If IsNumeric(GetSetting("MDBS", "Options", "SQLConnectionTimeout", "")) Then
5           OpenPublisherConnection.ConnectionTimeout = GetSetting("MDBS", "Options", "SQLConnectionTimeout", 30)
        End If
6       If IsNumeric(GetSetting("MDBS", "Options", "SQLCommandTimeout", "")) Then
7           OpenPublisherConnection.CommandTimeout = GetSetting("MDBS", "Options", "SQLCommandTimeout", 30)
        End If
8       OpenPublisherConnection.Open "Driver=SQL Server;" & _
            "SERVER=" & rsRepConfig!PublisherAddress & ";" & _
                "UID=" & DecryptString(Trim(rsRepConfig!PublisherLogin)) & ";" & _
                    "PWD=" & DecryptString(Trim(rsRepConfig!PublisherPassword)) & ";" & _
                        "DATABASE=" & rsRepConfig!PublisherDatabase
    End If
    Exit Function
ERROR_HANDLE:
9      CentralErrorHandler "frmCallMatco.OpenPublisherConnection"
    End If

End Function
--
CentralErrorHandler just displays the error message to the user, bypassing the displaying of some messages and then enters the error into a table to be transmitted to a central server for review.

The issue that I am seeing is occasionally I will get entries for this and other procedures that have a 0 error number and a 0 error line number.  Anyone have any ideas why these would kick to my error handler even though there is "technically" no error?

This is more of an annoyance then anything as I have added this to list of error numbers not to show to the user.

Thanks in advance for any assistance.
KOCUBAAsked:
Who is Participating?
 
justchat_1Connect With a Mentor Commented:
If there is an error with the ADODB.Connection then that will go into an error state but because the regular vb functions didnt cause an error the error code is still 0...
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
> Anyone have any ideas why these would kick to my error handler even though there is "technically" no error?
Probably there are places in your code that call it before Exit Sub or Exit Function, which means the code executes but err.number = 0

You can put this at the top of your error handler:

If err.Number = 0 then
   Exit Function
End IF
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
The problem is that when calling a procedure, the error variables get cleared.
you have to pass the values of Err.Number, Err.Source, Err.Description etc to the procedure CentralErrorHandler.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
KOCUBAAuthor Commented:
jimhorn,  As you can see from this procedure and all off the others that I have pop up with this issue they all contain the Exit Sub(or Function)  so that would not be the case.  

angellIII,  This works for handling errors thoughout the whole application this way so I do not need to pass those values.  

Just for some reason it is getting to the error handler withoout having an error.  I'm just wondering why.
0
 
EDDYKTCommented:
what's the GetLastError tell you if err is 0
0
 
KOCUBAAuthor Commented:
justchat_1,  Sounds possible but I do get error mesages for the ADODB.Connection.  Also I have procedures that don't reference that and still have these entries.

0
 
KOCUBAAuthor Commented:
EDDYKT,  Don't use that property currently but I can give it a try.
0
 
justchat_1Commented:
For more info on ADODB errors check this out:
http://support.sas.com/rnd/eai/oledb/app_error_objects.htm

it might be your problem...
0
 
justchat_1Commented:
It could be a combination of my suggestion and angelIII's suggestion... Many objects trap errors internally and will raise an error but you have to reference them not err.number to find out what it is...  It could also be error handlers that are accidently fired...
0
 
EDDYKTConnect With a Mentor Commented:
May be you shall also use err.LastDllError

Err.Number is always 0 because VB does not trap Win32 API errors. The LastDllError property, however, seems to work.


http://www.experts-exchange.com/Programming/Programming_Platforms/Win_Prog/Q_12018083.html
0
 
JR2003Commented:
angelIII is right when he says that the problem is that when calling a procedure, the error variables get cleared.
you have to pass the values of Err.Number, Err.Source, Err.Description etc to the procedure CentralErrorHandler
An alternative is to have in each error-trap  code that sets some global variables with the error code etc.

If you get mztools you can put in some standard error trapping and add it to each procedure with the click of a button.
0
 
justchat_1Commented:
yea didnt see that before...good call
0
 
KOCUBAAuthor Commented:
JR2003,  As I already stated..  This is not true because this is how it works thru out the whole application and I get correct error logs all the time.  The only possiblity with this thought is that there is some error that is happening and not getting logged then resetting the error variable.  But then the question is why?

And I do have and use mztools
0
 
JR2003Commented:
I'm sure it never used to do that when I used vb6?
0
 
justchat_1Commented:
I could have been right then:
"It could be a combination of my suggestion and angelIII's suggestion..."
0
 
KOCUBAAuthor Commented:
Thta's fine.  None of them are really correct but thanks for trying.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.