VBA / ADODB Run-Time Error: 3704
Domanda
La seguente subroutine VBA verrà eseguito maggior parte delle query più che bene. (Es: 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
Tuttavia, quando si esegue la query di seguito, il seguente messaggio di errore compare subito su: 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
Perché?
Soluzione 2
Ho appena ristrutturato la mia domanda ( link ), in modo che ho potuto mettere in una Visualizza. Poi ho creato una connessione in Excel per visualizzare il nome.
Altri suggerimenti
Se non ricordo male, l'oggetto ADO Command ha un timeout predefinito (30 secondi, credo), che possono essere la causa del problema: ci dovrebbe essere un ambiente come
cn.ConnectionTimeout = (your value here)
che si potrebbe estendere.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow