May be you should try setting CursorLocation
to adUseServer
...
Memory issue with query of huge table from Oracle database with ADO in Excel VBA
Pergunta
I need to use VBA to query a big data table (2.000.000 rows and 130 columns) from Oracle database and save it into text file.
The code I am using is the following
Dim DBConnection As ADODB.connection
Dim RecordSet As ADODB.RecordSet
'prepare string for connection
Dim strConnection As String
strConnection = "DRIVER=Oracle in OraClient11g_Home32;SERVER=" & database & " ;UID=" & username & ";PWD=" & password & ";DBQ=" & database & ";"
Set DBConnection = New ADODB.connection
'open connection
With DBConnection
.CommandTimeout = False
.ConnectionString = strConnection
.CursorLocation = adUseClient
.Open
End With
Set RecordSet = New ADODB.RecordSet
RecordSet.Open strSQLQuery, DBConnection, adOpenForwardOnly, adLockReadOnly
Do While RecordSet.EOF = False
str = ""
For x = 0 To RecordSet.Fields.Count - 1
If IsNumeric(RecordSet.Fields(x).Value) Then
dx = RecordSet.Fields(x).Value
str = str & Format(dx, "0.############") & delimiter
Else
str = str & RecordSet.Fields(x).Value & delimiter
End If
Next x
Print #FH, str
RecordSet.MoveNext
Loop
The problem is that probably ADO tries to store in the recordset all the queried data, which will be several GB of data, thus using too much RAM.
I need to find a way to limit the number of rows that are stored in RAM at one time, so that I can download and save as many row as I want without having any issue with the RAM.
I researched but I cannot find anything about this.
Thank you.
Solução
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow