Results 1 to 2 of 2
  1. #1
    uoghk is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jan 2022
    Posts
    149

    Data load very slow when not use Linked Table Manager

    I use Linked Table Manager to connect tables from SQL server.


    When running, data from SQL server can be retrieved very quickly.

    I want to connect the SQL tables without using the Linked Table Manager.
    I search the internet and the coding is below:
    Code:
    Function AttachDSNLessTable(stLocalTableName As String, stRemoteTableName As String, stServer As String, stDatabase As String, Optional stUsername As String, Optional stPassword As String)
        On Error GoTo AttachDSNLessTable_Err
        Dim td As TableDef
        Dim stConnect As String
    
    
        For Each td In CurrentDb.TableDefs
            If td.Name = stLocalTableName Then
                CurrentDb.TableDefs.Delete stLocalTableName
            End If
        Next
    
    
        If Len(stUsername) = 0 Then
            '//Use trusted authentication if stUsername is not supplied.
            stConnect = "ODBC;DRIVER=SQL Server;SERVER=" & stServer & ";DATABASE=" & stDatabase & ";Trusted_Connection=Yes"
        Else
            '//WARNING: This will save the username and the password with the linked table information.
            stConnect = "ODBC;DRIVER=SQL Server;SERVER=" & stServer & ";DATABASE=" & stDatabase & ";UID=" & stUsername & ";PWD=" & stPassword
        End If
        Set td = CurrentDb.CreateTableDef(stLocalTableName, dbAttachSavePWD, stRemoteTableName, stConnect)
        CurrentDb.TableDefs.Append td
        AttachDSNLessTable = True
        Exit Function
    
    
    AttachDSNLessTable_Err:
        AttachDSNLessTable = False
        MsgBox "AttachDSNLessTable encountered an unexpected error: " & Err.Description
    
    
    End Function
    At the start of my program, I attach all the tables eg:
    Call AttachDSNLessTable("Customer", "sqlCustomer", "SQLServer", "MyDatabase", "sa", "P@ssw0rd")
    Call AttachDSNLessTable("Order", "sqlOrder", "SQLServer", "MyDatabase", "sa", "P@ssw0rd")
    Call AttachDSNLessTable("OrderDetail", "sqlOrderDetail", "SQLServer", "MyDatabase", "sa", "P@ssw0rd")

    When user click Customer button, it shows customer list form.
    But it loads data very very slow and shows "Not Responding" in the header bar area.
    However, if I change back to use the Linked Table Manager, it load very fast.

    How can I improve it?
    Thanks

  2. #2
    darkwind is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Feb 2017
    Location
    Central U.S.
    Posts
    48
    I'm not quite sure what your purpose in attaching the tables at runtime is. There are some security-related reasons to do that, but you seem to be hard-coding in your passwords (not asking users to input that), so that doesn't seem to be a concern of yours. I'm not certain what your goal is here. Depending on what it is, there might be a different solution, still attaching tables via LTM and accomplishing your goal.

    Putting that aside, the first thing I'd look at is the connection strings. Attach a table via the linked table manager, then open it and look at its properties (F4). Check that connection string and see if there are settings there you aren't implementing in your VBA. Then add that in by adjusting AttachDSNLessTable().

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

Similar Threads

  1. Replies: 4
    Last Post: 05-22-2018, 10:35 AM
  2. Linked Table Manager
    By CS_10 in forum Access
    Replies: 3
    Last Post: 03-22-2016, 06:02 AM
  3. load csv data into linked table
    By acces2oracle in forum Programming
    Replies: 2
    Last Post: 09-12-2011, 04:47 AM
  4. Linked table manager error
    By jim_jim in forum Access
    Replies: 5
    Last Post: 08-25-2010, 08:06 PM
  5. Linked Table Manager
    By driccardi in forum Access
    Replies: 4
    Last Post: 02-15-2006, 11:47 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