rafalbballer
New Member
- Joined
- Aug 12, 2013
- Messages
- 19
Hi
i am using the code below to retrieve the data from SQL server database.
The only problem is when query gives me more than 1milion rows so not all the rows are imported into sheet.
Is there any workaround for this ?
thanks
i am using the code below to retrieve the data from SQL server database.
The only problem is when query gives me more than 1milion rows so not all the rows are imported into sheet.
Is there any workaround for this ?
thanks
Code:
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sConnString As String
Sheets("Projects").Activate
' Create the connection string.
sConnString = "Provider=SQLOLEDB;Data Source=moj server;" & _
"Initial Catalog=Datasources;" & _
"User ID=nazwa usera;" & _
"Integrated Security=SSPI;"
' Create the Connection and Recordset objects.
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
' Open the connection and execute.
conn.Open sConnString
conn.CommandTimeout = 20000
Set rs = conn.Execute("kwerenda")
' Check we have data.
' Check we have data.
If Not rs.EOF Then
' Transfer result.
Sheets("Projects").Range("A2").CopyFromRecordset rs
' Close the recordset
rs.Close
Else
MsgBox "Error: No records returned.", vbCritical
End If
' Clean up
If CBool(conn.State And adStateOpen) Then conn.Close
Set conn = Nothing
Set rs = Nothing