Results 1 to 3 of 3
  1. #1
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672

    Open Second Connection With 1st STill Open


    I am sure this is bad practice, but this is my syntax (would love pointers and re-writes on how to more efficiently perform this task) - what I do in the 1st method is query a database to get fullpathnames - then in the second method I again connect to SQL Server to query a database and get table names. Then I print the table names (in this example). My thought is, I am sure it has to be performance hog opening a connection twice, is there a way to re-write or alter this to make it more efficient?
    Code:
    Public Function GetDatabases()
    Dim c As ADODB.Connection,r As ADODB.Recordset,conn As String
    Set c = New ADODB.Connection
    Dim accapp As Database.Application
    Set accapp = New Database.Application
    With c
        .Provider = "sqloledb.1"
        With .Properties
            .Item("Data Source") = "Server"
            .Item("Initial Catalog") = "Database"
            .Item("PassWord") = "password"
            .Item("User ID") = "username"
        End With
        .Open
        Set r = c.Execute("SELECT Top 5 fullpath from dblocs")
        r.MoveFirst
        Do Until r.EOF
            Debug.Print r.Fields(0)
            accapp.OpenCurrentDatabase (r.Fields(0))
            accapp.Visible = True
    		'Calling method here with open connection and same variables
            CheckTabs
            Set accapp = Nothing
            r.MoveNext
        Loop
        r.Close
        Set rst = Nothing
        c.Close
    End With
    End Function
    Public Function CheckTabs()
    Dim c As ADODB.Connection, r As ADODB.Recordset, f As ADODB.Field, conn As String
    Set c = New ADODB.Connection
    With c
        .Provider = "sqloledb.1"
        With .Properties
            .Item("Data Source") = "Server"
            .Item("Initial Catalog") = "Database"
            .Item("PassWord") = "password"
            .Item("User ID") = "username"
        End With
        .Open
        Set r = .OpenSchema(adSchemaTables, Array(Empty, Empty, Empty, "TABLE"))
        With r
            While Not .EOF
                If (.Fields("TABLE_TYPE") = "TABLE" And .Fields("TABLE_NAME") Like "BlueBell*") Then
    				Debug.Print Mid(.Fields("Table_Name")
                End If
                .MoveNext
            Wend
        End With
    End With
    End Function

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    dim c2 as ADODB.connection

  3. #3
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    Quote Originally Posted by ranman256 View Post
    dim c2 as ADODB.connection
    I just simply need to rename the variables in the second procedure variable2

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 04-25-2014, 11:22 AM
  2. Replies: 2
    Last Post: 11-22-2013, 09:32 AM
  3. Replies: 2
    Last Post: 08-07-2013, 07:44 AM
  4. Replies: 4
    Last Post: 03-22-2012, 08:31 PM
  5. Replies: 2
    Last Post: 02-26-2010, 08:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums