ReportHacker
Programmer
Hi,
I am a newbie to VB (be kind) and have written a small VB DLL (v6.0) that is called from LabVIEW v6.1. The DLL connects and query's a large Citadel db ( and stores the 43200 rows and 100 ish column file (*.txt). I want to know if the following VB code is sound (no leaks) so I can focus on the LabVIEW code as the culprit.
Currently each time I run it through continuously it leaks 100-300k bytes. I've tried
just opening once then grabbing different ADO 2.5 recordsets, and opening each time
and grabbing a recordset. I'm using Windows 2000 Pro Service Pack 3, MDAC 2.5.
I don't know if any VB v6.0 service packs will help either - I'm having problems loading
VB ver6.0 service pack 5 as it can't find the installation (environ. path looks sound).
Option Explicit
'
Private dbConn As ADODB.Connection
Private connectionString As String
Private dbRec As ADODB.Recordset
'
Public Function GetCitadelData(ByVal CitadelDataDir As String, ByVal SQL_Text As String, ByVal NumRows As Long, ByVal TempFilename As String, ByVal OpenConnection As Boolean, ByVal CloseConnection As Boolean)
'
On Error GoTo Error_Handler
'
'
connectionString = "Provider=MSDASQL;" + _
"DRIVER={National Instruments Citadel 4 Database};" + _
"DbAppCharMap=@;" + _
"CitadelCharMap=.;" + _
"MaxColumnNameLength=62;" + _
"ConvertSpecialChars=1;" + _
"DaylightSavings=OS;" + _
"UTCBiasMinutes=OS;" + _
"DataDirectory=" + CitadelDataDir
Set dbConn = New ADODB.Connection ' Create connection object
dbConn.connectionString = connectionString
dbConn.Open
'
If (dbConn Is Nothing) Then
Exit Function
End If
'
connectionString = ""
'
Set dbRec = New ADODB.Recordset ' Create recordset object
dbRec.ActiveConnection = dbConn
'
dbRec.LockType = adLockReadOnly
dbRec.Open SQL_Text
dbRec.CacheSize = NumRows
'
If dbRec.BOF And dbRec.EOF Then
MsgBox "No Rows Returned"
Exit Function
End If
'
dbRec.Save TempFilename, adPersistXML
dbRec.MoveFirst
dbRec.CacheSize = 1
dbRec.Close
dbRec.Source = ""
dbRec.ActiveConnection = Nothing
Set dbRec = Nothing
'
'If CloseConnection = True Then
If (dbConn.State = adStateOpen) Then
dbConn.Close
Set dbConn = Nothing
End If
'End If
'
Exit Function
Error_Handler:
If (dbRec.State <> ADODB.adStateClosed) Then dbRec.Close
MsgBox "(" & Err.Number & "
: " & Err.Description, vbCritical + vbOKOnly
'
End Function
I am a newbie to VB (be kind) and have written a small VB DLL (v6.0) that is called from LabVIEW v6.1. The DLL connects and query's a large Citadel db ( and stores the 43200 rows and 100 ish column file (*.txt). I want to know if the following VB code is sound (no leaks) so I can focus on the LabVIEW code as the culprit.
Currently each time I run it through continuously it leaks 100-300k bytes. I've tried
just opening once then grabbing different ADO 2.5 recordsets, and opening each time
and grabbing a recordset. I'm using Windows 2000 Pro Service Pack 3, MDAC 2.5.
I don't know if any VB v6.0 service packs will help either - I'm having problems loading
VB ver6.0 service pack 5 as it can't find the installation (environ. path looks sound).
Option Explicit
'
Private dbConn As ADODB.Connection
Private connectionString As String
Private dbRec As ADODB.Recordset
'
Public Function GetCitadelData(ByVal CitadelDataDir As String, ByVal SQL_Text As String, ByVal NumRows As Long, ByVal TempFilename As String, ByVal OpenConnection As Boolean, ByVal CloseConnection As Boolean)
'
On Error GoTo Error_Handler
'
'
connectionString = "Provider=MSDASQL;" + _
"DRIVER={National Instruments Citadel 4 Database};" + _
"DbAppCharMap=@;" + _
"CitadelCharMap=.;" + _
"MaxColumnNameLength=62;" + _
"ConvertSpecialChars=1;" + _
"DaylightSavings=OS;" + _
"UTCBiasMinutes=OS;" + _
"DataDirectory=" + CitadelDataDir
Set dbConn = New ADODB.Connection ' Create connection object
dbConn.connectionString = connectionString
dbConn.Open
'
If (dbConn Is Nothing) Then
Exit Function
End If
'
connectionString = ""
'
Set dbRec = New ADODB.Recordset ' Create recordset object
dbRec.ActiveConnection = dbConn
'
dbRec.LockType = adLockReadOnly
dbRec.Open SQL_Text
dbRec.CacheSize = NumRows
'
If dbRec.BOF And dbRec.EOF Then
MsgBox "No Rows Returned"
Exit Function
End If
'
dbRec.Save TempFilename, adPersistXML
dbRec.MoveFirst
dbRec.CacheSize = 1
dbRec.Close
dbRec.Source = ""
dbRec.ActiveConnection = Nothing
Set dbRec = Nothing
'
'If CloseConnection = True Then
If (dbConn.State = adStateOpen) Then
dbConn.Close
Set dbConn = Nothing
End If
'End If
'
Exit Function
Error_Handler:
If (dbRec.State <> ADODB.adStateClosed) Then dbRec.Close
MsgBox "(" & Err.Number & "
'
End Function