2009-11-05 22 views
0

다음 VBA 서브 루틴은 대부분의 쿼리를 올바르게 실행합니다. (즉 : SELECT * FROM DUAL) 나는 아래의 쿼리를 실행할 때VBA/ADODB 런타임 오류 : 3704

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 

이유는 무엇입니까? 내가 올바르게 기억

+0

오라클 데이터베이스는 메모리 관리/연결 풀링 등을 통해 영리한 작업을 수행합니다. 쿼리 실행이 대기열에 있으면 연결 개체가 닫힌 것처럼 보일 수 있습니다. 주변에는 (a) 쿼리 최적화 및 (b) 통과 쿼리가 있습니다. – heferav

+0

h.hour에 null 값이 있습니까? – dendarii

+0

또는 샘플 테이블의 필드? – dendarii

답변

0

방금보기에 넣을 수 있도록 내 쿼리 (link)를 재구성했습니다. 그런 다음 이름을보기 위해 Excel에서 연결을 만들었습니다.

0

는 ADO Command 개체는 (30 초, 내가 생각하는) 문제를 일으킬 수있는 기본 시간 제한이 있습니다 : 당신이 확장 할 수

cn.ConnectionTimeout = (your value here) 

같은 설정이 있어야합니다.

+0

ConnectionTimeout 또는 CommandTimeout을 추가하면이 문제가 해결되지 않습니다. – Steven

+0

시간 초과로 인해 오류가 발생하지 않습니다. 그것은 "시간 초과"오류를 제공합니다. –