Re: Trapping ADO Connection Errors

From: DavidM (spam_at_spam.net)
Date: 12/29/04

  • Next message: Rob Charlton Jr.: "Asynchronous Cancel Problem VB 6.0 / ADODB / SQL Server"
    Date: Tue, 28 Dec 2004 21:49:56 -0600
    
    

    Thanks for the reply. Yes, I'm aware of it. I do not use classes -- I'm
    simply calling various functions that query the database and populate
    controls or collections.

    Basically, each function has an error handler. If an error occurs, I simply
    have my error handler call the following function:

    ' This routine displays ADO and VB errors
    Public Sub DisplayErrorMessage(strTitle As String)
       If gmobjConn.State = adStateOpen Then
          If gmobjConn.Errors.Count > 0 Then
             MsgBox "Error Code: " & gmobjConn.Errors(0).Number _
             & vbCrLf & "Description: " & gmobjConn.Errors(0).Description _
             & vbCrLf & "Source: " & gmobjConn.Errors(0).Source, _
             vbOKOnly + vbCritical, strTitle
          Else
             MsgBox "Error Code: " & Err.Number _
             & vbCrLf & "Description: " & Err.Description _
             & vbCrLf & "Source: " & Err.Source, _
             vbOKOnly + vbCritical, strTitle
          End If
       Else
          MsgBox "Error Code: " & Err.Number _
          & vbCrLf & "Description: " & Err.Description _
          & vbCrLf & "Source: " & Err.Source, _
          vbOKOnly + vbCritical, strTitle

       End If

    End Sub

    After this function returns, my error hanlder usually jumps back up a few
    lines to an "exit" label within my function, to reset various controls to
    disable and then exit function.

    In the original example that I gave, when my VPN connection is dropped while
    I have a connection open... and I'm in one of my routines reading a 10 row
    table or whatever... I appear to get hung in an endless loop.

    I'm just trying to figure out the best way to handle connection errors and
    so forth within my database code so users won't be stuck when something
    externally happens to the connection.

    "Veign" <NOSPAMinveign@veign.com> wrote in message
    news:%23t1PJNU7EHA.2180@TK2MSFTNGP12.phx.gbl...
    > You really haven't explain how you code is structured. Are you using
    > classes for the database function, common methods, one long procedure. Do
    > you have error handling in the functions / subs?
    >
    > Are you aware of the Error collection used by ADO:
    > http://www.devguru.com/Technologies/ado/quickref/connection_errorscollection.html
    >
    > --
    > Chris Hanscom - Microsoft MVP (VB)
    > Veign's Resource Center
    > http://www.veign.com/vrc_main.asp
    > --
    >
    > "DavidM" <spam@spam.net> wrote in message
    > news:eHfy6nS7EHA.2608@TK2MSFTNGP10.phx.gbl...
    >> I have a VB6 application that uses ADO to communicate with SQL Server
    > 2000.
    >> The application works fine, however I seem to have issues with trapping
    >> connection errors with ADO.
    >>
    >> I have a basic Error Handler in all my functions and display both VB and
    > ADO
    >> errors when they occur -- however, the problem I seem to be having is
    > this:
    >>
    >> 1) I create ADO Connection object and successfully log into SQL Server.
    > No
    >> problems.
    >>
    >> 2) I can create Recordset objects using Connection objects to perform
    >> various operations on my database.
    >>
    >> 3) However, if I disconnect my network cable or disconnect my VPN
    > connection
    >> to work while my application is idle doing nothing, and then attempt to
    >> perform a database operation... I normally get a slew of errors... some
    >> of
    >> which seem to get hung in a loop.
    >>
    >> Some of the errors are from when I try to open a recordset connection
    > within
    >> a With block or whatever other commands try and use an ADO command after
    > the
    >> connection is lost.
    >>
    >> What is the best way to handle this?
    >>
    >> Also, I currently display on the status bar "Connected" after a user
    >> successfully logins in an my ADO Connection object is created. I would
    > like
    >> to dynamically change this to "Disconnected" when I can no longer
    >> communicate with database.
    >>
    >> I assume, if this happens, I will have to have a way for the user to
    > attempt
    >> to log back into the application and re-create the connection object
    > atain.
    >>
    >> Anyone know the best way to handle this?
    >>
    >>
    >>
    >
    >


  • Next message: Rob Charlton Jr.: "Asynchronous Cancel Problem VB 6.0 / ADODB / SQL Server"

    Relevant Pages

    • Re: ODBC/OLE DB Connection Pool
      ... > connection be kept open for the application as this will serialize all ... threads ONCE they are returned to the pool. ... > Tips for ADO Users ... > The ADO Connection object implicitly uses IDataInitialize. ...
      (microsoft.public.data.ado)
    • Re: ODBC/OLE DB Connection Pool
      ... > connection be kept open for the application as this will serialize all ... threads ONCE they are returned to the pool. ... > Tips for ADO Users ... > The ADO Connection object implicitly uses IDataInitialize. ...
      (microsoft.public.inetserver.asp.db)
    • Re: ODBC/OLE DB Connection Pool
      ... > connection be kept open for the application as this will serialize all ... threads ONCE they are returned to the pool. ... > Tips for ADO Users ... > The ADO Connection object implicitly uses IDataInitialize. ...
      (microsoft.public.data.oledb)
    • Re: Reading with ADO from Access database over network
      ... I suspect the *problem* isn't the failure to open the folder ... check the active Connection ... Perhaps you could follow the above instructions and post the *ADO* ... > exclusively the database. ...
      (microsoft.public.excel.programming)
    • Re: Reading with ADO from Access database over network
      ... Is your ADO code trying to open the Connection with exclusive locks ... If so, instead consider locking the ... workgroups security so the database is only locked when someone with ...
      (microsoft.public.excel.programming)

  • Quantcast