ADO Error Handling....Newbie Question... 
Author Message
 ADO Error Handling....Newbie Question...

Hi All,
    how do I intercept ADO errors, so I can use my own error handling.
For example;

------------------------------------------------------------------------------------

On Error GoTo ErrorTrap

    sConnect = dbexp_get_connection_str(connect string)

    Set conn = New ADODB.Connection
    conn.ConnectionString = sConnect

    conn.Open
    conn.Close
    Exit Sub

ErrorTrap:
    MsgBox "Press Enter To Continue", vbOKOnly, "Connection Error"
------------------------------------------------------------------------------------

if I pass an invalid connect string, I get a runtime error, not my error
handling

TIA

Bill



Thu, 09 Jan 2003 03:00:00 GMT  
 ADO Error Handling....Newbie Question...

Quote:
> Hi All,
>     how do I intercept ADO errors, so I can use my own error handling.
> For example;

Bill,  Here's a code snippet from a Microsoft example.  This formats
for XML, but it's easy to change it for text files.  Jamie

Public Function GetADOError(ByVal ADOErrors As ADODB.Errors) As String

    Dim sXML As String
    Dim oADODBError As ADODB.Error

    For Each oADODBError In ADOErrors
        sXML = sXML & "<ADODBError>"
        With oADODBError
            sXML = sXML & T("Description", .Description)
            sXML = sXML & T("HelpContext", .HelpContext)
            sXML = sXML & T("HelpFile", .HelpFile)
            sXML = sXML & T("NativeError", .NativeError)
            sXML = sXML & T("Number", .Number)
            sXML = sXML & T("Source", .Source)
            sXML = sXML & T("SQLState", .SQLState)
        End With
        sXML = sXML & "</ADODBError>"
    Next

    clsError_GetADOError = sXML
End Function

Private Function T(Name As String, Value As String) As String
    T = "<" & Name & ">" & Value & "</" & Name & ">" & vbCrLf
End Function

Sent via Deja.com http://www.deja.com/
Before you buy.



Fri, 10 Jan 2003 03:00:00 GMT  
 ADO Error Handling....Newbie Question...
Thanks.

Bill

Quote:


> > Hi All,
> >     how do I intercept ADO errors, so I can use my own error handling.
> > For example;

> Bill,  Here's a code snippet from a Microsoft example.  This formats
> for XML, but it's easy to change it for text files.  Jamie

> Public Function GetADOError(ByVal ADOErrors As ADODB.Errors) As String

>     Dim sXML As String
>     Dim oADODBError As ADODB.Error

>     For Each oADODBError In ADOErrors
>         sXML = sXML & "<ADODBError>"
>         With oADODBError
>             sXML = sXML & T("Description", .Description)
>             sXML = sXML & T("HelpContext", .HelpContext)
>             sXML = sXML & T("HelpFile", .HelpFile)
>             sXML = sXML & T("NativeError", .NativeError)
>             sXML = sXML & T("Number", .Number)
>             sXML = sXML & T("Source", .Source)
>             sXML = sXML & T("SQLState", .SQLState)
>         End With
>         sXML = sXML & "</ADODBError>"
>     Next

>     clsError_GetADOError = sXML
> End Function

> Private Function T(Name As String, Value As String) As String
>     T = "<" & Name & ">" & Value & "</" & Name & ">" & vbCrLf
> End Function

> Sent via Deja.com http://www.deja.com/
> Before you buy.



Fri, 10 Jan 2003 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Newbie Question: VBScript Error handling and Session Timeout

2. Question on ADO Deadlock Error Handling

3. newbie file handling question

4. Newbie question: database handling

5. Newbie Clipboard Metafile Handle Question

6. Getting a winddow's handle and then sending text to it (very newbie question)

7. newbie: Access error handling

8. Newbie: SQL error handling in VB

9. Error handling in component - Newbie

10. newbie error handling problem

11. Error handling newbie, help please

12. Plz HELP! Newbie Question: How to handle errors in ADO-Vb when an action is Canceled?

 

 
Powered by phpBB® Forum Software