Groups | Blog | Home
all groups > dotnet ado.net > may 2007 >

dotnet ado.net : Checking db connection open status


rowe_newsgroups
5/3/2007 9:08:16 AM
[quoted text, click to view]

Check the connection's State property.

Thanks,

Seth Rowe
William (Bill) Vaughn
5/3/2007 10:59:13 AM
Ah, checking the State might not help. It merely indicates the state that
ADO.NET "thinks" the connection is in--Open or Closed (or some others).
While this might be enough, you won't know if the connection is viable until
you try to use it.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
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.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
-----------------------------------------------------------------------------------------------------------------------

[quoted text, click to view]

John
5/3/2007 5:01:47 PM
Hi

I am creating a db connection using the below code. Is there a way to check
if the connection is open?

Thanks

Regards


= Code Below ====================

Dim LocalConn As OleDb.OleDbConnection
Dim St As String = My.Settings.LocalDBConnectionString

LocalConn = New OleDb.OleDbConnection(St)
LocalConn.Open()

Patrice
5/3/2007 6:14:15 PM
Try :
http://msdn2.microsoft.com/en-us/library/system.data.oledb.oledbconnection.state(VS.71).aspx

If you don't have a local documentation, you'll find the class library
reference at :
http://msdn2.microsoft.com/en-us/library/ms229335.aspx

---
Patrice

"John" <John@nospam.infovis.co.uk> a écrit dans le message de news:
enIrbxZjHHA.4188@TK2MSFTNGP02.phx.gbl...
[quoted text, click to view]

Miha Markic
5/3/2007 11:42:20 PM
Why do you need to check its status anyway?

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

[quoted text, click to view]
Miha Markic
5/4/2007 12:00:00 AM
I think the best way to deal with connection errors is to cacth them and try
to re-open the connection. As Bill mentioned there is no way to know for
sure whether the connection is ok or not.
However, I suggest that one should always use the approach to open as late
as possible and close asap the connection.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

[quoted text, click to view]
John
5/4/2007 1:21:44 AM
So if it is closed for anyone reason it can be re-opened before executing a
query. Sort of trying to avoid the above mentioned error.

Regards

[quoted text, click to view]

AddThis Social Bookmark Button