Reading a linked ODBC table never returns
Environment
Own VBA code that reads linked ODBC or OData tables with DAO Recordset.GetRows, in any Access
version, with the Microsoft ODBC Driver 18 for SQL Server or the Wkl OData driver; other drivers
are not supported.
Cause
When the source fails in the middle of a result - a row the server cannot compute, a data service
answering 429 (too many requests), a lost connection - GetRows never returns: DAO calls the
driver's SQLFreeStmt in a loop on one thread at 100 % CPU, and Access hangs until it is ended.
MoveNext over the same records raises error 3146 (“ODBC call failed”) instead.
The WKL controls read with MoveNext and show the error (DataError, or the error text in the
control); they are not affected. Own code that fills arrays for them, or for anything else, is.
Resolution
Read linked tables with a
MoveNextloop instead ofGetRows, and handle error 3146:Dim rs As DAO.Recordset, n As Long On Error GoTo ReadFailed Set rs = CurrentDb.OpenRecordset("SELECT ID, Name FROM tblKunde", dbOpenSnapshot) Do Until rs.EOF n = n + 1 rs.MoveNext Loop Exit Sub ReadFailed: ' 3146: the source failed while reading; DBEngine.Errors may hold the driver's text Debug.Print Err.Number, DBEngine.Errors(0).Description- Reading one field object per column once, outside the loop (
Set fName = rs!Name), keeps the loop about as fast asGetRows. - A process that already hangs can only be ended in the task manager; unsaved work in that Access is lost.