Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Database Connection Error Number from ADO 1

Status
Not open for further replies.

skyplayer

Programmer
May 28, 2002
13
HK
What is the error number of the Database Connection Error from ADO, when there is a physical connection break during the program operation?
Any error constant about it?
I tried one error number is 2147220401.
Any suggestion, thanks a lot!
 
If you lose connection during your program you may get different error nubers depending on what your program is doing or attempts to do. I don't think there is one 'catch-all' error -214... error number.

Also remember that 214... error numbers are negative, so make sure that you include the negative symbol (-214....), I have made that mistake myself.

You will probably have to purposfully destroy your connection at different points in your program and see what error you get. Or handle all -214... errors the same, which could have its own problems. Thanks and Good Luck!

zemp
 
Thx for yr reply, zamp.
Ya, I forgot the -ve sign, it should be -2147220401,
but I found that the err number is different from which level of function call.
E.g. A() call B(), B() raise database connecion error to A(),
For the err.number in B() = -2147467259
For the err.number in A() raise from B() = -2147220401

Thus, I would like to know all the err number about the database error, so that I won't miss any error number raise from database connection.
Or I can just simply check if the 1st 3 number of err number is "-214XXXXXX"?
Any reference can I refer for the err.number?Thanks very much.
 
To find all the error numbers you will have to search the microsoft site. But I wouldn't be surprised if the list of -214.... errors is constantly being updated. I would try to handle each error in each sub or function as they come up. This means that stringent testing needs to be done so that none are missed. What I like to do is handle the specific errors that I know about and send the rest to my error messaging function where I can see the error, error number and the procedure that it has occured in. I found that this makes debugging a bit easier and I can keep the program from crashing. Thanks and Good Luck!

zemp
 
If you're using ADO, then as part of the connection object, there is a collection of error objects which contain information about ADO errors. You can walk thru this error collection in your normal error handler with code similar to the following: (gADO_Connect is the ADO Connection Object). Although its not used in this code, the ADO Error Ojbect also has a number property.

Dim lRst_Error As ADODB.Error

lStr_NewLine = vbCrLf & vbTab & Space(3) ' Custom New Line
If (gADO_Connect.Errors.Count > 0) Then
For Each lRst_Error In gADO_Connect.Errors
With lRst_Error
lStr_ErrDesc = vbNullString
lStr_ErrParts = Split(.Description, "]")
For lInt_Idx = 0 To UBound(lStr_ErrParts)
lStr_ThisErr = Trim(lStr_ErrParts(lInt_Idx))
If (Left(lStr_ThisErr, 1) = "[") Then
lStr_ThisErr = lStr_ThisErr & "]"
End If
lStr_ErrDesc = lStr_ErrDesc & lStr_ThisErr & lStr_NewLine
Next lInt_Idx
lStr_Msg = lStr_Msg & lStr_ErrDesc & lStr_NewLine & _
"(Source" & vbTab & vbTab & ": " & .Source & ")" & lStr_NewLine & _
"(SQL State" & vbTab & ": " & .SQLState & ")" & lStr_NewLine & _
"(NativeError" & vbTab & ": " & .NativeError & ")" & vbCrLf
End With
Next
Set lRst_Error = Nothing
Else
' Not an ADO Error - so handle normally
End If
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
CajunCenturion, thanks for posting. Looks great, I'll be using it myself. Thanks and Good Luck!

zemp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top