2016-07-27 79 views
1

我有一個在本地使用SQL Server 2012 Express的應用程序,它帶有一個帶有窗體,宏和模塊的Microsoft Access 2016前端。它被用於現場收集檢測數據,包括許多照片。問題是,當插入到主遠程SQL Server 2012時,出現錯誤:MS Access 2013,SQL Server 2012 Express,查詢超時

Microsoft ODBC SQL Server Driver error: Query timeout expired

如果用戶附加了超過3張照片。

到目前爲止,我已經嘗試提高遠程SQL Server(屬性\連接)上的遠程查詢超時,我已將服務器刷新間隔提高到240秒(工具\選項)。我在訪問中添加代碼到VBA在SQL函數:

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 

最後我已經添加‘連接超時= 90’到連接字符串的末尾在VBA:

Server=localhost\SQLEXPRESS2012;Database=DamInspector; 

測試更新腳本只需要67秒運行,但我已經從‘0’嘗試的各種時間長度(無限)到1024. T他具體的運行時錯誤是'-2147217871(80040e31)'[微軟] [ODBC SQL Server驅動程序]查詢超時已過期
也許是不同的方法?
我有14個表格,必須由11名檢查員同步。其中7張是用於照片的。在SQL Express的每個本地實例上運行存儲過程而不是通過鏈接表使用VBA編寫腳本會更好嗎?

+0

我想你會在這裏需要一個不同的方法。 ODBC查詢並不適合在潛在不穩定的網絡上傳輸太多數據(相對於網絡速度)。某種背景傳輸(FTP?)。 – Andre

+0

它不會上傳照片文件,但會在表格中顯示BLOB數據。 – DLWyer

+0

是的,我明白了,那是恕我直言的問題。我的意思是*非常*不同的方法,或者根本不將照片存儲在數據庫中,或者一旦通過不同的頻道上傳照片,則通過服務器進程插入它們。 – Andre

回答

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 

這可能全部放在一個程序中,但是在這個階段,我需要知道,如果在遠程服務器上插入問題,它會在哪裏出現問題。到目前爲止這麼好,但我們纔開始。

+0

完成。它只是在全州推出,所以我最初沒有列出代碼。 – DLWyer