【发布时间】:2021-01-11 18:46:12
【问题描述】:
我得到 Operation is not allowed when object is closed 错误。
为什么我会收到此错误? [错误位置][2]
连接没有问题。
我可以在同一个 cmd 连接上进行 SQL 查询,并且没有任何问题。
只有这个查询把我搞砸了。
我通常不使用设置搜索路径或表短名称,但只是以防万一 这次讲的很详细。
当我在 PostgreSQL 中运行相同的查询时,我得到了结果:
[同一 SQL 查询的 postgres 输出][1]
我已经在谷歌上搜索了几个小时,但找不到任何答案。 它与驱动程序有关系吗? 我如何知道我使用的 Excel 驱动程序是什么? 我应该使用什么驱动程序? 如何更换驱动程序?
[我使用的参考资料][3]
- https://i.stack.imgur.com/R4nLe.png
- https://i.stack.imgur.com/k4uJo.png
- https://i.stack.imgur.com/Ytrlk.png
代码
Public Function getDBArray(cmd, strSQL)
Dim recordID As Long, recordAmount As Long, totalFields As Integer, fieldID As Integer
Dim rs As New ADODB.Recordset
Set rs = CreateObject("ADODB.Recordset")
cmd.CommandText = strSQL '' << this is the strSQL i copy pasted directly to pgadmin and it worked
Set rs = cmd.Execute
totalFields = getTableAmount(rs.Fields)
recordAmount = getTableAmount(rs) ' << error in this function
recordID = 0
【问题讨论】:
-
根据您的第二个屏幕截图,错误实际上发生在函数
getTableAmount()中,您应该将其添加到您的帖子中。