A strange problem

vnarod

Regular
Joined
Mar 22, 2002
Messages
84
My program hangs after several clicks that access database.
It does not matter what items I click, even if I click the same two buttons that are calling the same sub it hangs after a few times (everytime different number).

I have no idea where to start investigating. Can someone
show me the right direction?

All I do with database is get a DataReader:
Dim dr As OleDbDataReader = oDbAccess.GetData(sSQL)
Return dr

Public Function GetData(ByVal sSQL As String) As OleDbDataReader
Dim oCmd As OleDbCommand = New OleDbCommand(sSQL, cn)
Dim myReader As OleDbDataReader
Try
myReader = oCmd.ExecuteReader()
Return myReader
Catch e As OleDbException
MsgBox(e.Message)
cn.Close()
End Try
End Function
 
You are closing you connection in the Catch, you should do it in the Finally section. While you're at i verify the State first...
Visual Basic:
Catch e As OleDbException
    MsgBox(e.Message)
Finally
    if cn.state = [i]something[/i].Opened then cn.Close()
'sorry, I don't have .NET handy

End Try
 
Thank you. Unfortunately, there are no errors in this case so Catch never gets executed anyway.
 
That means that your connection remains open. As I said, place the cn.close in the Finally.

Finally allways gets excecuted.
 
But connection is supposed to stay open. I open it at the beggining and close when application ends. Why would multiple ExecuteReaders (around 20) make the program hang?
 
Back
Top