G
Guest
I am attempting to refresh links to a backend SQL database. Would like to
have capability to test connection and also be able to switch backend
databases when necessary. When experimenting with this, determined that
refreshing the links is painfully slow (seems to vary from 1 - 60 seconds per
table depending on size of table), whereas just deleting the table and
recreating is much faster (maybe 1-2 seconds per table). Would prefer to
refreshlink over delete/create. Per previous posts on this, I tried to keep
backend open via dbODBC in code below (did not make a difference; maybe
because backend is SQL and not mdb). Any thoughts on why performance is so
poor?
Public Sub Refresher()
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim strConnect As String
Dim strServer As String
Dim strDatabase As String
Dim intCounter as integer
Dim dbODBC As Database
strServer = "MyServerName"
strDatabase = "MyDbName"
strConnect = "ODBC;DRIVER={SQL Server}" _
& ";SERVER=" & strServer _
& ";DATABASE=" & strDatabase _
& ";INTEGRATED SECURITY=SSPI"
Set db = CurrentDb()
Set dbODBC = OpenDatabase("", False, False, strConnect)
For intCounter = 0 To db.TableDefs.Count - 1
Set tdf = db.TableDefs(intCounter)
If tdf.SourceTableName <> "" Then
Debug.Print "Refresh table: " & tdf.Name
tdf.Connect = dbODBC.Connect
tdf.RefreshLink
Debug.Print "Done table: " & tdf.Name
End If
Next intCounter
Set tdf = Nothing
Set db = Nothing
Set dbODBC = Nothing
End Sub
have capability to test connection and also be able to switch backend
databases when necessary. When experimenting with this, determined that
refreshing the links is painfully slow (seems to vary from 1 - 60 seconds per
table depending on size of table), whereas just deleting the table and
recreating is much faster (maybe 1-2 seconds per table). Would prefer to
refreshlink over delete/create. Per previous posts on this, I tried to keep
backend open via dbODBC in code below (did not make a difference; maybe
because backend is SQL and not mdb). Any thoughts on why performance is so
poor?
Public Sub Refresher()
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim strConnect As String
Dim strServer As String
Dim strDatabase As String
Dim intCounter as integer
Dim dbODBC As Database
strServer = "MyServerName"
strDatabase = "MyDbName"
strConnect = "ODBC;DRIVER={SQL Server}" _
& ";SERVER=" & strServer _
& ";DATABASE=" & strDatabase _
& ";INTEGRATED SECURITY=SSPI"
Set db = CurrentDb()
Set dbODBC = OpenDatabase("", False, False, strConnect)
For intCounter = 0 To db.TableDefs.Count - 1
Set tdf = db.TableDefs(intCounter)
If tdf.SourceTableName <> "" Then
Debug.Print "Refresh table: " & tdf.Name
tdf.Connect = dbODBC.Connect
tdf.RefreshLink
Debug.Print "Done table: " & tdf.Name
End If
Next intCounter
Set tdf = Nothing
Set db = Nothing
Set dbODBC = Nothing
End Sub