G
Guest
I have an intermittant problem that occurs a couple of times a week in a
handful of places in the code (the same places at different times). The
error is 'Object reference not set to an instance of an object'. After much
research (it's not my code), I've found that it is occuring when a datareader
is being used after being returned from a another method that queries an
Oracle database. Here is the method:
Public Function GetDataReader(ByVal strSelect As String) As
OleDbDataReader
Dim rc As Integer
Const FUNCTION_NAME As String = CLASS_NAME + ":SelectSQL"
Try
objConn = New OleDbConnection(strConnectionString)
objCmd = New OleDbCommand(strSelect, objConn)
objCmd.Connection.Open()
GetDataReader =
objCmd.ExecuteReader(CommandBehavior.CloseConnection)
Catch ex As OleDbException
If oLogFile Is Nothing Then oLogFile = New clsLogFile()
rc = oLogFile.LogErrorMessage(FUNCTION_NAME, ex.ErrorCode,
ex.Message + " SQL Statement: |" + strSelect + "|")
GetDataReader = Nothing
Finally
objConn = Nothing
objCmd = Nothing
End Try
End Function
As I mentioned above, the error is occurring the first time the returned
datareader is used in the calling code. The first thing the calling code
does is check to see if the returned datareader is closed. When this
statement executes the datareader object does not exist. Here is an example
of the calling code:
oDatabase = New ICPT.clsDatabase(oSession.ApplicationConnectionString,
oSession.DatabaseType)
strSQL = "SELECT * FROM TransactionCodes"
rdrTranCode = oDatabase.GetDataReader(strSQL)
'verify the datareader is open and contains a record
If rdrTranCode.IsClosed = False Then '' bomb on this line
'do something
End If
I've checked the application log files and there is no indication that the
GetDataReader() method is trapping and logging an error. Any of you guys see
a problem with this code? It looks as if a database connection and
subsequent query are being done successfully (nothing in error logs), but
when the datareader is returned the reference to the datareader is lost.
I can tell you that most of the things this application does involve at
least a few calls to GetDataReader(), and sometimes there are quite a few
calls to perform a certain function. I've checked the Oracle log and trace
files and there is no indication of anything flaky.
Any ideas?
Thanks,
Todd
handful of places in the code (the same places at different times). The
error is 'Object reference not set to an instance of an object'. After much
research (it's not my code), I've found that it is occuring when a datareader
is being used after being returned from a another method that queries an
Oracle database. Here is the method:
Public Function GetDataReader(ByVal strSelect As String) As
OleDbDataReader
Dim rc As Integer
Const FUNCTION_NAME As String = CLASS_NAME + ":SelectSQL"
Try
objConn = New OleDbConnection(strConnectionString)
objCmd = New OleDbCommand(strSelect, objConn)
objCmd.Connection.Open()
GetDataReader =
objCmd.ExecuteReader(CommandBehavior.CloseConnection)
Catch ex As OleDbException
If oLogFile Is Nothing Then oLogFile = New clsLogFile()
rc = oLogFile.LogErrorMessage(FUNCTION_NAME, ex.ErrorCode,
ex.Message + " SQL Statement: |" + strSelect + "|")
GetDataReader = Nothing
Finally
objConn = Nothing
objCmd = Nothing
End Try
End Function
As I mentioned above, the error is occurring the first time the returned
datareader is used in the calling code. The first thing the calling code
does is check to see if the returned datareader is closed. When this
statement executes the datareader object does not exist. Here is an example
of the calling code:
oDatabase = New ICPT.clsDatabase(oSession.ApplicationConnectionString,
oSession.DatabaseType)
strSQL = "SELECT * FROM TransactionCodes"
rdrTranCode = oDatabase.GetDataReader(strSQL)
'verify the datareader is open and contains a record
If rdrTranCode.IsClosed = False Then '' bomb on this line
'do something
End If
I've checked the application log files and there is no indication that the
GetDataReader() method is trapping and logging an error. Any of you guys see
a problem with this code? It looks as if a database connection and
subsequent query are being done successfully (nothing in error logs), but
when the datareader is returned the reference to the datareader is lost.
I can tell you that most of the things this application does involve at
least a few calls to GetDataReader(), and sometimes there are quite a few
calls to perform a certain function. I've checked the Oracle log and trace
files and there is no indication of anything flaky.
Any ideas?
Thanks,
Todd