ADO Recordset Not Staying Open in VBA - “Operation is not allowed when the object is closed”

后端 未结 3 886
我在风中等你
我在风中等你 2021-01-21 07:41

I don\'t really understand what has happened here. I\'m using Excel VBA to connect to a SQL Server Express database and return an ADO Recordset. I had it working initially, but

3条回答
  •  太阳男子
    2021-01-21 08:33

    I had a similar issue and found two things that killed the query results over ODBC

    • Count of intermediate values for processing before the final output. Fixed with "set nocount on" at the start of the query

    • null values being aggregated away - running the query directly on SQL Server showed the message "Warning: Null value is eliminated by an aggregate or other SET operation." Fixed by chasing down each of them and either replacing with empty strings, zeros or whatever low value makes sense and doesn't impact the query results.

    I think in both cases the warning message was output before the records, so the storage recordset was 'filled' with that warning, but no data. On SQL Server, these warnings silently sit in the message log but don't impact the query results, so the temptation is to let them be and move on to higher priority work.

提交回复
热议问题