B
Bryan
I'm sure this is a basic question, but I'm just not getting it.
I'm using a Try / Catch block to surround my database access code. For
example:
Try
cmdDBCommand = New SqlCommand("dbo.GetMonthlyBilling", oConnection)
cmdDBCommand.CommandType = CommandType.StoredProcedure
cmdDBCommand.Parameters.Add("@CustomerID", iCustomerID)
dtrReader = cmdDBCommand.ExecuteReader
If dtrReader.HasRows Then
dtrReader.Read()
bResult = dtrReader.Item("BillMonthly")
End If
dtrReader.Close()
Catch ex As Exception
bResult = False
End Try
The problem is this -- if there is a problem with the try block, we
jump to the Catch and the reader is not closed.
If I just blindly close it in the catch, I may get an error saying that
it's not open.
So, how can I safely check the reader to see if it needs to be closed?
Thanks in advance for your help!
- Bryan
I'm using a Try / Catch block to surround my database access code. For
example:
Try
cmdDBCommand = New SqlCommand("dbo.GetMonthlyBilling", oConnection)
cmdDBCommand.CommandType = CommandType.StoredProcedure
cmdDBCommand.Parameters.Add("@CustomerID", iCustomerID)
dtrReader = cmdDBCommand.ExecuteReader
If dtrReader.HasRows Then
dtrReader.Read()
bResult = dtrReader.Item("BillMonthly")
End If
dtrReader.Close()
Catch ex As Exception
bResult = False
End Try
The problem is this -- if there is a problem with the try block, we
jump to the Catch and the reader is not closed.
If I just blindly close it in the catch, I may get an error saying that
it's not open.
So, how can I safely check the reader to see if it needs to be closed?
Thanks in advance for your help!
- Bryan