我们有一个访问应用程序(拆分为前端和后端),它使用以下代码重新链接表:
Private Function ReconnectTables() As Boolean
On Error Resume Next
Dim tdf As DAO.TableDef
Dim dbs As DAO.Database
Dim strPath As String
Dim strConnect As String
Set dbs = CurrentDb
strConnect = "\\dfs\prd\departmentX\DepartmentalApplicationX_be.accdb"
For Each tdf In dbs.TableDefs
If tdf.Connect <> "" Then
tdf.Connect = ";DATABASE=" & strConnect
tdf.RefreshLink
End If
Next
Set dbs = Nothing
If Err.Number = 0 Then ReconnectTables = True
End Function
单个用户使用时效果很好,但是当第二个用户尝试访问时,会挂起(大约需要5分钟)。
有什么方法可以避免这种情况吗?看起来我有两个选择:
感谢分享你的智慧!
答案 0 :(得分:1)
试试这个:
Set dbs = CurrentDb
strConnect = ";DATABASE=\\dfs\prd\departmentX\DepartmentalApplicationX_be.accdb"
For Each tdf In dbs.TableDefs
If tdf.Connect <> "" and tdf.Connect<> strConnect Then
tdf.Connect = strConnect
tdf.RefreshLink
End If
Next
因此,只有在必要时才会重新连接。