yablonka Posted May 20, 2003 Posted May 20, 2003 How can verify that my connection is still alive after the Connetion.Open method was already called succefully? Thank you. Quote
archer_coal Posted May 20, 2003 Posted May 20, 2003 RE Dim conn_state as string conn_state = Myconnection.State Label1.Text = conn_state 1 = open 0 = closed Quote
yablonka Posted May 20, 2003 Author Posted May 20, 2003 Thanks but, I tried it and as far as I could see Connection.State does not update, i.e. once the connection is established the Connection.State gets the value of "1" and then if the connection is lost (because of network problems or anything like that) Connection.State does not contain "0" but remains "1". Quote
dsgreen57 Posted May 20, 2003 Posted May 20, 2003 I hear where you are coming from this one... and it is a right pain in the arse the only way I found to get around it is to write a connection class, which maintains your connection and have a method such as GetConnection()... within this attempt some operation, which accesses the database, wrap this in a try block and then re-open a connection if it fails. If someone has a solution other than this then I would love to hear it as it has been driving me mad trying to find a better way. Quote
wyrd Posted May 20, 2003 Posted May 20, 2003 You don't have to write some custom class for this. There's a ConnectionState enumerator which you can use. 'Valid values of ConnectionState are Closed, Connecting, 'Open, Executing, Fetching, and Broken. If (cn.State And ConnectionState.Open) <> 0 Then cn.Close End If On top of this, there's also the StateChange event you can use that triggers whenever the state of a connection changes. Quote Gamer extraordinaire. Programmer wannabe.
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.