Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm too late to give you a useful answer to your question, but I came <em>here</em> because I wanted to see if StaCkOverflow has a better answer than the code I'm currently using to test ADODB connections.</p> <p>...It turns out that the answer is 'No', so I'll post the code for reference: someone else will find it useful.</p> <p>Coding notes: this isn't a generic answer: it's a method from a class encapsulating the ADODB.Connection object, and it assumes the existence of object 'm_objConnect'.</p> <p><strong>TestConnection: a VBA Class method for publishing debugging information for an ADODB.Connection object</strong></p> <p>This prints out the connection string, the current status, a list of ADODB errors (if any) and a full listing of the onnection's named properties.</p> <p> <PRE></p> <p>Public Sub TestConnection() On Error GoTo ErrTest</p> <p>Dim i As Integer</p> <p>If m_objConnect Is Nothing Then</p> <pre><code>Debug.Print "Object 'm_objConnect' not instantiated." </code></pre> <p>Else</p> <pre><code>Debug.Print m_objConnect.ConnectionString Debug.Print "Connection state = " &amp; ObjectStateString(m_objConnect.State) Debug.Print If m_objConnect.Errors.Count &gt; 0 Then Debug.Print "ADODB ERRORS (" &amp; m_objConnect.Errors.Count &amp; "):" For i = 0 To m_objConnect.Errors.Count With m_objConnect.Errors(i) Debug.Print vbTab &amp; i &amp; ":" _ &amp; vbTab &amp; .Source &amp; " Error " &amp; .Number &amp; ": " _ &amp; vbTab &amp; .Description &amp; " " _ &amp; vbTab &amp; "(SQL state = " &amp; .SqlState &amp; ")" End With Next i End If Debug.Print Debug.Print "CONNECTION PROPERTIES (" &amp; m_objConnect.Properties.Count &amp; "):" For i = 0 To m_objConnect.Properties.Count - 1 Debug.Print vbTab &amp; i &amp; ":" _ &amp; vbTab &amp; m_objConnect.Properties(i).Name &amp; " = " _ &amp; vbTab &amp; m_objConnect.Properties(i).Value Next i </code></pre> <p>End If</p> <p>ExitTest: Exit Sub ErrTest: Debug.Print "Error " &amp; Err.Number &amp; " raised by " &amp; Err.Source &amp; ": " &amp; Err.Description Resume Next</p> <p>End Sub</p> <p>Private Function ObjectStateString(ObjectState As ADODB.ObjectStateEnum) As String</p> <p>Select Case ObjectState Case ADODB.ObjectStateEnum.adStateClosed ObjectStateString = "Closed" Case ADODB.ObjectStateEnum.adStateConnecting ObjectStateString = "Connecting" Case ADODB.ObjectStateEnum.adStateExecuting ObjectStateString = "Executing" Case ADODB.ObjectStateEnum.adStateFetching ObjectStateString = "Fetching" Case ADODB.ObjectStateEnum.adStateOpen ObjectStateString = "Open" Case Else ObjectStateString = "State " &amp; CLng(ObjectState) &amp; ": unknown state number" End Select</p> <p>End Function</p> <p></PRE> </p> <p>Share and enjoy: and watch out for line-breaks, helpfully inserted where they will break the code by your browser (or by StackOverflow's formatting functions).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload