代码之家  ›  专栏  ›  技术社区  ›  Steven

vba/adodb运行时错误:3704

  •  0
  • Steven  · 技术社区  · 15 年前

    下面的vba子例程将运行大多数查询。(I: 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 回复  |  直到 9 年前
        1
  •  0
  •   davek    15 年前

    如果我记得正确的话,ADO命令对象有一个默认的超时(我想是30秒),这可能会导致您的问题:应该有一个类似

    cn.ConnectionTimeout = (your value here)
    

    你可以延长。

        2
  •  0
  •   Community    7 年前

    我刚刚重新组织了我的查询( link 以便我能把它放在一个视图中。然后我在Excel中创建了一个连接来查看名称。