ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to determine if a connection is active (https://www.excelbanter.com/excel-programming/331872-how-determine-if-connection-active.html)

[email protected]

How to determine if a connection is active
 
I am writing an addin that manages an ODBC/OLEDB connection to a
database. I manage to make the connection without trouble. However, I
would like to be able to determine if the connection is still active;
for instance, the database might drop the connection if a certain
amount of time has passed without activity. How can I determine if a
connection is active?

Many thanks,

Phil


keepITcool

How to determine if a connection is active
 


check the .State property
of the adodb.Connection object

anyway..
you should not needlessly leave the connection open.
close it when done. reopen when need.

--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


wrote :

I am writing an addin that manages an ODBC/OLEDB connection to a
database. I manage to make the connection without trouble. However,
I would like to be able to determine if the connection is still
active; for instance, the database might drop the connection if a
certain amount of time has passed without activity. How can I
determine if a connection is active?

Many thanks,

Phil


[email protected]

How to determine if a connection is active
 
That works fine. I'm testing for .State = 1 to determine if a
connection is active. Would you happen to know the values that .State
can take on? I'm sorry to ask, but the ADODB help library isn't
installed on any of the machines I have access to.

And I agree with you that I shouldn't needlessly leave the connection
open. But I have rather a strange situation where it makes some sort
of sense to let the user manage the connection rather than trying to do
it in my program, and I prefer to test if the connection exists rather
than trap the error that occurs if it doesn't exist.

Thanks for the help.

Phil


keepITcool

How to determine if a connection is active
 
object browser:
state

enum ObjectStateEnum

adstateclosed
adstateconnecting
adstateexecuting
adstatefetching
adstateopen

for reference:
http://msdn.microsoft.com/library/de.../en-us/ado270/
htm/mdmscadoapireference.asp

(or search msdn for adodb api reference)

i often use:
www.devguru.com Ado Quick Reference
http://www.devguru.com/Technologies/...ado_intro.html


--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


wrote :

That works fine. I'm testing for .State = 1 to determine if a
connection is active. Would you happen to know the values that .State
can take on? I'm sorry to ask, but the ADODB help library isn't
installed on any of the machines I have access to.

And I agree with you that I shouldn't needlessly leave the connection
open. But I have rather a strange situation where it makes some sort
of sense to let the user manage the connection rather than trying to
do it in my program, and I prefer to test if the connection exists
rather than trap the error that occurs if it doesn't exist.

Thanks for the help.

Phil


[email protected]

How to determine if a connection is active
 
Excellent reference. Thank you. I should have searched harder after
finding the appropriate help file wasn't loaded.

Thanks,

Phil



All times are GMT +1. The time now is 06:59 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com