C
Custom Creations For Kids
We have used VBA in Excel 2002 to create an application making data
calls to a SQL database. Initially the application runs quickly making
multiple select statements to get the data into Excel. The longer the
application is used without being closed the longer each data call
takes. Once the Excel workbook is closed and reopened we are back to
very quick SQL calls again. We are using adodb connections to connect
to the database (see example below). It seems that there is a thread
that is not closing out for some reason, that is disconnected once we
close Excel.
Any ideas how to kill the connection/thread so that we can retain the
fast performance speed?
Thanks so much!
***********************************************
Sub selectData(strSELECT As String, strWksht As String, strStartCell As
String)
'Use this as a generic SELECT statement to return data and copy it
starting in the cell strStartCell
Dim cnPubs As ADODB.Connection
Set cnPubs = New ADODB.Connection
Dim strConn As String
strConn = "PROVIDER=SQLOLEDB;"
strConn = strConn & "DATA SOURCE=****;INITIAL CATALOG=****;"
strConn = strConn & " user Id=****;Password=*****;"
cnPubs.Open strConn
Dim rsPubs As ADODB.Recordset
Dim oCmd As New ADODB.Command
Dim oRSet As ADODB.Recordset
Set rsPubs = New ADODB.Recordset
With rsPubs
.ActiveConnection = cnPubs
.Open strSELECT
Worksheets(strWksht).Range(strStartCell).CopyFromRecordset rsPubs
.Close
End With
cnPubs.Close
Set rsPubs = Nothing
Set cnPubs = Nothing
End Sub
********************************************************
calls to a SQL database. Initially the application runs quickly making
multiple select statements to get the data into Excel. The longer the
application is used without being closed the longer each data call
takes. Once the Excel workbook is closed and reopened we are back to
very quick SQL calls again. We are using adodb connections to connect
to the database (see example below). It seems that there is a thread
that is not closing out for some reason, that is disconnected once we
close Excel.
Any ideas how to kill the connection/thread so that we can retain the
fast performance speed?
Thanks so much!
***********************************************
Sub selectData(strSELECT As String, strWksht As String, strStartCell As
String)
'Use this as a generic SELECT statement to return data and copy it
starting in the cell strStartCell
Dim cnPubs As ADODB.Connection
Set cnPubs = New ADODB.Connection
Dim strConn As String
strConn = "PROVIDER=SQLOLEDB;"
strConn = strConn & "DATA SOURCE=****;INITIAL CATALOG=****;"
strConn = strConn & " user Id=****;Password=*****;"
cnPubs.Open strConn
Dim rsPubs As ADODB.Recordset
Dim oCmd As New ADODB.Command
Dim oRSet As ADODB.Recordset
Set rsPubs = New ADODB.Recordset
With rsPubs
.ActiveConnection = cnPubs
.Open strSELECT
Worksheets(strWksht).Range(strStartCell).CopyFromRecordset rsPubs
.Close
End With
cnPubs.Close
Set rsPubs = Nothing
Set cnPubs = Nothing
End Sub
********************************************************