C
Cc
hi,
while I making my own class library using odbc.net I encounter strange
problem
in this class
Public Sub New()
' some code doing openning connection
end sub
Protected Overrides Sub Finalize()
'somecode doing closing connection
MyBase.Finalize()
End Sub
the idea in here is to save trouble from openning and closing connection .
in this class I have some function
Private Function executeSQL_Q(ByVal arg_SQL As String, Optional ByVal
arg_isStoredProc As Boolean = False) As OdbcDataReader
Try
Dim m_oCmd As New OdbcCommand
m_oCmd.Connection = loc_DBconn
If arg_isStoredProc Then
m_oCmd.CommandType = CommandType.StoredProcedure
Else
m_oCmd.CommandType = CommandType.Text ''default
End If
m_oCmd.CommandText = arg_SQL
Return m_oCmd.ExecuteReader
Catch eX As System.Exception
Throw
End Try
End Function
----------------------------------------------------------------------------
--------------------------------------------
Public Function version() As String
Dim retval As String
Try
Dim m_oReader As OdbcDataReader
m_oReader = executeSQL_Q("select VERSION();")
m_oReader.Read()
retval = m_oReader.Item("VERSION()")
m_oReader.Close()
Catch eX As Exception
Throw
End Try
Return retval
End Function
as you see this is only a very simple function. when calling this class
function once and exist program it work fine, the problem only occur
whenever I call this function more than once and exit the program that
reference this class will get unhandle error (I can't get the error even
though I use try and catch exception).
after a while I finaly found where this error occur. to solve this I must
manual close the connection rather than let the finalize procedure do it for
me
Is there a way to let it the close connection at finalize rather than I have
to manualy close without having this error ?
while I making my own class library using odbc.net I encounter strange
problem
in this class
Public Sub New()
' some code doing openning connection
end sub
Protected Overrides Sub Finalize()
'somecode doing closing connection
MyBase.Finalize()
End Sub
the idea in here is to save trouble from openning and closing connection .
in this class I have some function
Private Function executeSQL_Q(ByVal arg_SQL As String, Optional ByVal
arg_isStoredProc As Boolean = False) As OdbcDataReader
Try
Dim m_oCmd As New OdbcCommand
m_oCmd.Connection = loc_DBconn
If arg_isStoredProc Then
m_oCmd.CommandType = CommandType.StoredProcedure
Else
m_oCmd.CommandType = CommandType.Text ''default
End If
m_oCmd.CommandText = arg_SQL
Return m_oCmd.ExecuteReader
Catch eX As System.Exception
Throw
End Try
End Function
----------------------------------------------------------------------------
--------------------------------------------
Public Function version() As String
Dim retval As String
Try
Dim m_oReader As OdbcDataReader
m_oReader = executeSQL_Q("select VERSION();")
m_oReader.Read()
retval = m_oReader.Item("VERSION()")
m_oReader.Close()
Catch eX As Exception
Throw
End Try
Return retval
End Function
as you see this is only a very simple function. when calling this class
function once and exist program it work fine, the problem only occur
whenever I call this function more than once and exit the program that
reference this class will get unhandle error (I can't get the error even
though I use try and catch exception).
after a while I finaly found where this error occur. to solve this I must
manual close the connection rather than let the finalize procedure do it for
me
Is there a way to let it the close connection at finalize rather than I have
to manualy close without having this error ?