Color scheme: Light
You are here: start » en » Documentation » Microsoft Access development tools » WKL Forms Object Library » WKL Forms Object Library troubleshooting » Reading a linked ODBC table never returns

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

  1. Read linked tables with a MoveNext loop instead of GetRows, 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
  2. Reading one field object per column once, outside the loop (Set fName = rs!Name), keeps the loop about as fast as GetRows.
  3. A process that already hangs can only be ended in the task manager; unsaved work in that Access is lost.
en/wiki/msaccess/comctl/troubleshooting/reading-a-linked-table-never-returns.txt · Last modified: by Wolfgang van der Stille