vnarod Posted March 24, 2003 Posted March 24, 2003 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 Quote
Moderators Robby Posted March 24, 2003 Moderators Posted March 24, 2003 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... 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 Quote Visit...Bassic Software
vnarod Posted March 24, 2003 Author Posted March 24, 2003 Thank you. Unfortunately, there are no errors in this case so Catch never gets executed anyway. Quote
Moderators Robby Posted March 24, 2003 Moderators Posted March 24, 2003 That means that your connection remains open. As I said, place the cn.close in the Finally. Finally allways gets excecuted. Quote Visit...Bassic Software
vnarod Posted March 25, 2003 Author Posted March 25, 2003 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? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.