VBA / ADODB运行时错误:3704
题
下面的VBA子程序将运行大多数的查询就好了。 (即:SELECT * FROM DUAL
)
Sub DisplayQuery(QueryString As String)
Dim rs As New ADODB.Recordset
Dim connStr As String
connStr = _
"Provider=MSDAORA.1;" _
& "User ID=abc;Password=123;" _
& "Data Source=xxx/xxx;"
out QueryString
rs.Open QueryString, connStr, adOpenStatic, adLockOptimistic
Range("DataTable").Clear
Cells(1, 1).CopyFromRecordset rs
End Sub
然而,当我运行下面的查询时,下面的错误消息立即弹出:Run-time error '3704':Operation is not allowed when the object is closed.
with all_hours as
( select to_date('2009-11-03 05:00 PM','yyyy-mm-dd hh:mi PM') + numtodsinterval(level-1,'hour') hour
from dual
connect by level <= 4 /*hours*/
)
select h.hour
, count(case when h.hour = trunc(s.sampled_on,'hh24') then 1 end) sampled
, count(case when h.hour = trunc(s.received_on,'hh24') then 1 end) received
, count(case when h.hour = trunc(s.completed_on,'hh24') then 1 end) completed
, count(case when h.hour = trunc(s.authorized_on,'hh24') then 1 end) authorized
from all_hours h cross join sample s
group by h.hour
为什么?
解决方案 2
我刚刚改组我的查询(链接),这样我可以把它变成一个视图。然后,我创建Excel中的一个连接,以查看名称
其他提示
如果我没有记错,ADO Command对象有一个默认的超时时间(30秒,我认为),这可能会导致您的问题:应该有像
设置cn.ConnectionTimeout = (your value here)
这可以扩展。
不隶属于 StackOverflow