ActiveConnection Property Example

The following examples illustrates use of the ActiveConnection property to select an rdoConnection. In this case, the application opens two separate connections and uses the same rdoQuery against each.

Dim rdoCn As New rdoConnection
Dim rdoCn2 As New rdoConnection
Dim rdoQy As New rdoQuery
Dim rdoRs As rdoResultset
Dim rdoCol As rdoColumn
Dim rdoEn As rdoEnvironment

Private Sub Form_Load()
On Error GoTo CnEh

Set rdoEn = rdoEnvironments(0)

With rdoCn

    .Connect = "UID=;PWD=;Database=WorkDB;" _
        & "Server=Betav486;Driver={SQL Server}" _
        & "DSN='';"
    .LoginTimeout = 5
    .EstablishConnection rdDriverNoPrompt, True
    rdoEn.rdoConnections.Add rdoCn
End With

With rdoCn2
    .Connect = "UID=;PWD=;Database=Pubs;" _
        & "Server=Betav486;Driver={SQL Server}" _
        & "DSN='';"
    .LoginTimeout = 5
    .EstablishConnection rdDriverNoPrompt, True
    rdoEn.rdoConnections.Add rdoCn2
End With

With rdoQy
    Set .ActiveConnection = rdoCn
    .SQL = "Select Name, refDate " _
      & " from Sysobjects where type = 'U' "
    .LockType = rdConcurReadOnly
    .RowsetSize = 1
    .CursorType = rdUseServer
End With

For Each rdoCn In rdoEn.rdoConnections
    Set rdoQy.ActiveConnection = rdoCn
    Set rdoRs = rdoQy.OpenResultset(rdOpenForwardOnly)
    With rdoRs
        For Each rdoCol In rdoRs.rdoColumns
            Debug.Print rdoCol.Name,
        Next
        Debug.Print
        Do Until rdoRs.EOF
                For Each rdoCol In rdoRs.rdoColumns
                    Debug.Print rdoCol
                Next
            rdoRs.MoveNext
        Loop
    End With
Next                    ' Next Connection
    
Exit Sub
CnEh:
Dim er As rdoError
    Debug.Print Err, Error
    For Each er In rdoErrors
        Debug.Print er.Description, er.Number
    Next er
    Resume Next
End Sub