我有一个ADODB连接,可以检索45k行和48列数据。查询在不到1秒的时间内执行,但copyformrecordset行执行时间超过15分钟。有谁知道为什么这么慢?
更新:添加Connection.CursorLocation = adUseClient
会将延迟移至记录集开放行,并使copyfromrecordset几乎立即生效。我不确定这是否有助于缩小为什么它仍然需要15分钟的原因。我看到其他人在几秒钟内发布了60k +行。
Sub HarvestData()
Application.ScreenUpdating = False
Dim Connection As ADODB.Connection
Dim rs As ADODB.Recordset
Dim QT As Excel.QueryTable
Dim ConnectionString As String
Dim SQL As String
Set Connection = New ADODB.Connection
Set Rs1 = New ADODB.Recordset
'Making the call to the database
ConnectionString = Myconnectionstringishere
'The query that is being pulled
SQL = Sheets("SQL").Range("B13").Value
'This is executing the SQL query
Connection.Open ConnectionString
Rs1.Open SQL, Connection, adOpenForwardOnly, adLockReadOnly
'This is defining a location for the data to be pasted
Set Location = ActiveWorkbook.Sheets("Sheet1")
'This is pasting the data
Location.Range("b2").CopyFromRecordset Rs1
'These are closing the connections I opened
Rs1.Close
Connection.Close
Application.ScreenUpdating = True
End Sub
答案 0 :(得分:0)
我无法告诉您的SQL查询是什么,但我将其用作我的粘贴命令...
With ActiveSheet.Cells(2, 2)
rec_QTY = .CopyFromRecordset(Rs1)
End With
我涉猎大量数据库记录......而且这个命令通常很快。 单元格(2,2)与范围(" B2")
相同