ADO Connection State Does Not Reflect Actual Connection State 
Author Message
 ADO Connection State Does Not Reflect Actual Connection State

If you open an ADO connection to SQL Server then
  the connection.State = 1

If SQL was shutdown or the network connection broken then
  the connection.State would still = 1

Is there a way to tell if the ADO Connection Object lost its connection to
SQL Server without trying to execute a SQL statement?



Wed, 25 May 2005 03:10:53 GMT  
 ADO Connection State Does Not Reflect Actual Connection State
Dan,

State property DOES NOT reflect live state of connection. It show state of
connection at the moment of time when it was attempt to open it. So there is
no direct way in ADO to find out if connection still alive or not, rather
than executing SQL statement against connection and get error

--
Val Mazur
Microsoft MVP


Quote:
> If you open an ADO connection to SQL Server then
>   the connection.State = 1

> If SQL was shutdown or the network connection broken then
>   the connection.State would still = 1

> Is there a way to tell if the ADO Connection Object lost its connection to
> SQL Server without trying to execute a SQL statement?



Wed, 25 May 2005 04:54:19 GMT  
 ADO Connection State Does Not Reflect Actual Connection State
We've gone over this before, and the result was "not really". ADO does not
actually "open" the connection, nor monitor its state so it has no way of
knowing if the connection or the server it connects to is still alive. The
connection pool mechanism does the "real" open, but it also does not attempt
to "poll" the server to see if the connection is still viable.
We agreed that the best way is to either poll yourself (run a low-impact
query) or simply be prepared for a broken connection in your application.

hth

--
________________________________
William (Bill) Vaughn, Author, Trainer, Mentor
Microsoft Pacwest Regional Director, MVP
"ADO.NET and ADO Examples and Best Practices for VB Programmers--2nd
Edition" (ISBN: 1-893115-68-2)
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
________________________________

Quote:
> If you open an ADO connection to SQL Server then
>   the connection.State = 1

> If SQL was shutdown or the network connection broken then
>   the connection.State would still = 1

> Is there a way to tell if the ADO Connection Object lost its connection to
> SQL Server without trying to execute a SQL statement?



Wed, 25 May 2005 04:57:03 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. ?ADO connection state when deleting Tabledef - Jet3.51?

2. ADO Connection state

3. Maintaining State - DB Connection

4. Outlook Connection State ...

5. Outlook Connection State

6. Internet Connection State using wininet.dll and InternetGetConnectedStateEx

7. Preserving Connection state in Application object

8. Connection.State Property

9. How to check state of TCP/IP connection

10. How to check state of TCP/IP connection

11. Internet Connection State?

12. How to check state of TCP/IP connection

 

 
Powered by phpBB® Forum Software