I have an app using SQL Server 2012 Express on the local with a Microsoft Access 2016 frontend with forms, macros and modules. It is used in the field to gather inspection data, including many photographs. The problem is that when inserting to the main remote SQL Server 2012 I get an error:
Microsoft ODBC SQL Server Driver error: Query timeout expired
if the user attaches more than 3 photos.
Thus far I’ve tried raising the Remote query timeout on the remote SQL Server (Properties\Connections), I've raised the server refresh interval to 240 seconds (Tools\Options). I've added code to the VBA in the SQL function in Access:
Dim Conn As ADODB.Connection
Set Conn = New ADODB.Connection
Conn.ConnectionTimeout = 120
And I’ve added the following function to the AutoExec macro that runs when the app starts:
Function SetTimeout()
Dim Mydb As Database
Set Mydb = CurrentDb
Mydb.QueryTimeout = 640
End Function
Finally I've added "Connection Timeout=90" to the end of the connection string in VBA:
Server=localhost\SQLEXPRESS2012;Database=DamInspector;
A test update script only takes 67 seconds to run but I've tried various lengths of time from "0" (infinite) to 1024. The specific Run-time error is '-2147217871 (80040e31)' [Microsoft][ODBC SQL Server Driver]Query timeout expired
Perhaps a different method?
I have 14 tables that must be synced by 11 inspectors. 7 of the tables are for photos. Would it be better to run a stored procedure on each local instance of SQL Express rather than scripting with VBA through the linked tables?
The solution for me was to create the process in stored procedures on the local instance of SQL Server and call it from the MS Access form. I also created a small function to create the procedures on each user's PC so I didn't have to manually do so. Since this had to be distributed to users statewide, the action takes place in Access. To add the procedures necessary to upload the inspection data and pictures I created a function for each following this format:
Then I created the function to call the each stored procedure:
It is possible that this could have all been put in one procedure, but at this stage I needed to know, if there were issues inserting to the remote server, where was it breaking down. So far so good, but we've only begun.