B
Brent
I wrote a simple class to supply a datareader object (code at bottom of
post) back to a page. I access it on the APSX page like this:
Dim myDR as New getDataReader(strSQL)
If myDR.ResultFailed = True Then
MessageText.InnerHTML = "Internal error."
Else
dataList.DataSource = myDR.Result
dataList.DataBind()
End If
From time to time it get weird errors, which I tend to think stem from not
closing the database connection in the class code. Yet, if I explicitly
close the connection, I get an error that says "Invalid attempt to
FieldCount when reader is closed. " I've commented-out the
connection-closing code below, and this code actually works. Is there any
way I can make sure the connection gets closed in hopes of preventing the
other random errors?
Thanks for any help!
--Brent
*===================================
Public Class getDataReader
Public Result AS OLEDBDatareader
Public ResultFailed as Boolean = True
Public Sub New(strSQL AS String)
Try
Dim myConn as new OleDBConnection (connString)
myConn.Open()
Dim myCommand AS new OleDBCommand(strSQL, myConn)
Result = myCommand.ExecuteReader()
ResultFailed = False
'myConn.Close()
myConn = Nothing
Catch
ResultFailed = True
End Try
End Sub
End Class
===================================
post) back to a page. I access it on the APSX page like this:
Dim myDR as New getDataReader(strSQL)
If myDR.ResultFailed = True Then
MessageText.InnerHTML = "Internal error."
Else
dataList.DataSource = myDR.Result
dataList.DataBind()
End If
From time to time it get weird errors, which I tend to think stem from not
closing the database connection in the class code. Yet, if I explicitly
close the connection, I get an error that says "Invalid attempt to
FieldCount when reader is closed. " I've commented-out the
connection-closing code below, and this code actually works. Is there any
way I can make sure the connection gets closed in hopes of preventing the
other random errors?
Thanks for any help!
--Brent
*===================================
Public Class getDataReader
Public Result AS OLEDBDatareader
Public ResultFailed as Boolean = True
Public Sub New(strSQL AS String)
Try
Dim myConn as new OleDBConnection (connString)
myConn.Open()
Dim myCommand AS new OleDBCommand(strSQL, myConn)
Result = myCommand.ExecuteReader()
ResultFailed = False
'myConn.Close()
myConn = Nothing
Catch
ResultFailed = True
End Try
End Sub
End Class
===================================