Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
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".
Posted

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.

Posted

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.

Gamer extraordinaire. Programmer wannabe.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...