ADO adStateOpen and connection timeout

Hi, sometimes my connection (Dim cn as new ADODB.Connection) may timeout. And when the program tries to access the cn again, it will give error "The application requested an operation on an object with a reference to a closed or or invalid connections object".

So I added the following code to detect whether cn is still open or not :

If cn.State <> adStateOpen Then
   cn.ConnectionString = connectionStr
End If

However, I find that it does not work. It still give the a/m error or "not connected to ORACLE".

Is there any other way I can detect if the connection has already timeout so I can make a connection again?

My environment is NT, VB6, Oracle.

Who is Participating?
AnswerTheManConnect With a Mentor Commented:
first you sould wrote :
                If cn.State <> adStateClose Then
                   cn.ConnectionString = connectionStr
                End If
But even that -  don't count on the adStateClose in this case.
the meaning of the msg you get is that some objects in your application
(Controls probably), which were bound to the DB through the Connection(CN)
were left without it.
you should search your code for such cases. if found - you should set their
DataMember="", so they will lose their connection with CN. later - reconnect them.
now, the same is for Recordsets based on this connection. Closing them is not
enough, and you MUST Set them to NOTHING. otherwize - you face this conflict
of what's looks like a Closed connection, but leaving objects orpaned.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.