1

我有一个在本地使用 SQL Server 2012 Express 的应用程序,带有 Microsoft Access 2016 前端,带有表单、宏和模块。它用于现场收集检查数据,包括许多照片。问题是当插入到主远程 SQL Server 2012 时出现错误:

Microsoft ODBC SQL Server 驱动程序错误:查询超时已过期

如果用户附加了 3 张以上的照片。

到目前为止,我已尝试提高远程 SQL Server(属性\连接)上的远程查询超时,我已将服务器刷新间隔提高到 240 秒(工具\选项)。我在 Access 的 SQL 函数中向 VBA 添加了代码:

Dim Conn As ADODB.Connection
Set Conn = New ADODB.Connection
Conn.ConnectionTimeout = 120

我已将以下函数添加到应用程序启动时运行的 AutoExec 宏中:

Function SetTimeout()
      Dim Mydb As Database
      Set Mydb = CurrentDb
      Mydb.QueryTimeout = 640
  End Function

最后,我在 VBA 的连接字符串末尾添加了“Connection Timeout=90”:

Server=localhost\SQLEXPRESS2012;Database=DamInspector; 

测试更新脚本只需要 67 秒即可运行,但我尝试了从“0”(无限)到 1024 的各种时间长度。具体的运行时错误是 '-2147217871 (80040e31)' [Microsoft][ODBC SQL Server Driver]Query timeout expired
也许有不同的方法?
我有 14 个表必须由 11 个检查员同步。其中7张桌子用于照片。在 SQL Express 的每个本地实例上运行存储过程而不是通过链接表使用 VBA 编写脚本会更好吗?

4

1 回答 1

1

我的解决方案是在本地 SQL Server 实例的存储过程中创建进程,并从 MS Access 表单中调用它。我还创建了一个小函数来在每个用户的 PC 上创建程序,因此我不必手动执行此操作。由于这必须在全州范围内分发给用户,因此该操作在 Access 中进行。为了添加上传检查数据和图片所需的程序,我为每个以下格式创建了一个函数:

Function CreateProcAppendToAncillaryPics()
    'Change mouse to hour glass so end user knows something is going on
    Screen.MousePointer = 11

    Dim Conn As ADODB.Connection
        Set Conn = New ADODB.Connection
        Dim strCreateProcAncillaryImages As String
        Conn.Open ("Driver={SQL Server};Server=localhost\SQLEXPRESS2012;Database=DamInspector")

        strCreateProcAncillaryImages = "CREATE PROCEDURE dbo.AppendToAncillaryPics AS " & _
    "INSERT INTO [xxx.xxx.xxx.xxx].DamInspector.dbo.AncillaryImages " & _
                "(tableVersion, ID, techUName, DamsPhoto, PhotoDescription, structName, marker, thisdate, uuid)" & _
                " SELECT " & _
                    "L.tableVersion, L.ID, L.techUName, L.DamsPhoto, L.PhotoDescription, L.structName, L.marker, L.thisdate, L.uuid" & _
                " FROM DamInspector.dbo.AncillaryImages AS L" & _
                    " LEFT OUTER JOIN " & _
                    "[xxx.xxx.xxx.xxx].DamInspector.dbo.AncillaryImages AS R " & _
                    "ON L.uuid = R.uuid " & _
                "WHERE " & _
                    "R.uuid IS NULL;"

    Conn.Execute strCreateProcAncillaryImages
    Conn.Close
    'Set the mouse pointer back to normal
    Screen.MousePointer = 0
'Notify the user the process is complete.
    MsgBox "Upload Process Completed."
End Function

然后我创建了调用每个存储过程的函数:

Function Call_ProcAppendToGeneralPics()
Screen.MousePointer = 11
    Dim Conn As ADODB.Connection
        Set Conn = New ADODB.Connection
        Conn.Open ("Driver={SQL Server};Server=localhost\SQLEXPRESS2012;Database=DamInspector")

        Conn.Execute "AppendToAncillaryPics"
        Conn.Execute "AppendToAuxSpillwayPics"
        Conn.Execute "AppendToCrestPics"
        Conn.Execute "AppendToDownstreamPics"
        Conn.Execute "AppendToGeneralPics"
        Conn.Execute "AppendToOcPics"
        Conn.Execute "AppendToRiserPics"
        Conn.Execute "AppendToUpstreamPics"

    Conn.Close
    Screen.MousePointer = 0
'Notify the user the process is complete.
    MsgBox "Upload Process Completed."
End Function

有可能这一切都可以放在一个程序中,但在这个阶段我需要知道,如果插入远程服务器有问题,它在哪里发生故障。到目前为止一切顺利,但我们才刚刚开始。

于 2016-08-20T22:35:19.193 回答