Database connection does not close?!?

Okay. I think I have tolerated this long enough. At first it was just a little annoyance, now it completely ticks me off and is taking up too much of my time.

Whenever I use a OledbDataReader on a page, it locks up my MS Access Database with a .lbd file.

I use a DataHandler vb page for calling my function for using the datareader. Here is the function within my DataHandler:

Public

Shared Function GetDataReader(ByVal strSQL As String, ByVal strConn As String) As OleDbDataReader

Dim dr As OleDbDataReader

Dim cmd As New OleDbCommand

With cmd

.Connection =

New OleDbConnection(strConn)

.Connection.Open()

.CommandText = strSQL

dr = .ExecuteReader(CommandBehavior.CloseConnection)

End With

Return dr

End Function

I thought that "dr = .ExecuteReader(CommandBehavior.CloseConnection)" would close the connection. Apparently there is something going on with this. Here is an example of when I am calling this function and it locks up the db:

strSQL =

String.Format("SELECT COUNT(*) AS Answer FROM Survey WHERE [4EC]<6")

Try

dr = DataHandler.GetDataReader(strSQL, strConn)

Do While dr.Read

Session("4ECa") = dr("Answer")

Loop

answer = Session("4ECa")

answer2 = Session("4EC")

final = (answer / answer2) * 100

lblECa.Text = final.ToString & "%"

Catch ex As Exception

lblError.Text = ex.Message

End Try

I am not exactly sure if this is the particular sub that locks the file. I have tried determining, but it almost seems random to me. I usually have to turn off my PC and come back after 5-10 minutes in order for the .ldb file to disappear and stop causing problems.

When it is locked up, some of my pages begin giving me an "Unspecified Error" message. It seems like this error is always caused by a connection not being closed (according to my research). That is what I thought I had taken care of in my DataHandler.GetDataReader function.

Anybody have any suggestions or even comments on this? Am I not seeing something that I am doing?

Thank you,

Kerry


Respect to the community...

KJAK
0
KJAK
5/17/2006 6:54:50 PM
asp.net.access-datasource 4679 articles. 0 followers. Follow

0 Replies
352 Views

Similar Articles

[PageSpeed] 29

Reply: