performance - 多用户情况下重新链接数据库缓慢

标签 performance ms-access vba ms-access-2010

我们有一个 Access 应用程序(分为前端和后端),它使用以下代码重新链接表:

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

当单个用户使用时,此功能运行良好,但一旦第二个用户尝试 Access 此功能,就会挂起(大约需要 5 分钟)

有什么办法可以避免这种情况吗?看起来我有两个选择:

  1. 如果可能,提高重新链接的性能。 这将如何完成?
  2. 完全避免应用程序发布到生产环境后立即重新链接表。我不确定这是否可取?如果我每次都停止重新链接表格,是否仍然可以检测到是否需要以某种方式重新链接

感谢您分享您的智慧!

最佳答案

试试这个:

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

因此,仅在必要时才应进行重新连接。

关于performance - 多用户情况下重新链接数据库缓慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20996477/

相关文章:

vba - 显示 "Number stored as Text"错误

excel - "Automation Error: Object Invoked has disconnected from its clients"

perl - 数字和字符串自动转换对效率没有影响吗?

sql - 做一个双重用途的查询,还是两个单独的查询?

mysql - SQL查询以查找连接表行的计数作为每行的摘要

sql - 使用 select 和 where 子句更新查询

vba - 使用静态分析使开发更好

.net - .NET 内存管理在托管代码中是否比在 native 代码中更快?

sql-server - 在不同的设置上使 SQL Server 中的 Microsoft Access 表相同

sql-server - 如何将 data.txt 和 attributes.txt 以及 mapping.sql 获取到关系数据库