469,923 Members | 1,781 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,923 developers. It's quick & easy.

Closing database connection.

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
===================================
Nov 18 '05 #1
0 992

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by C Sharp beginner | last post: by
6 posts views Thread by Steven Blair | last post: by
4 posts views Thread by Brent | last post: by
7 posts views Thread by darrel | last post: by
7 posts views Thread by Arsalan | last post: by
3 posts views Thread by Andy G | last post: by
1 post views Thread by Vegar Hansen | last post: by
7 posts views Thread by Martien van Wanrooij | last post: by
5 posts views Thread by zacks | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.