|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Checking db connection open statusHi
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()
Show quote
Hide quote
On May 3, 12:01 pm, "John" <J...@nospam.infovis.co.uk> wrote: Check the connection's State property.> 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() Thanks, Seth Rowe 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.4***@TK2MSFTNGP02.phx.gbl...Show quoteHide quote > 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() > > 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. -- Show quoteHide quote____________________________________ 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) ----------------------------------------------------------------------------------------------------------------------- "John" <John@nospam.infovis.co.uk> wrote in message news:enIrbxZjHHA.4188@TK2MSFTNGP02.phx.gbl... > 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() > > Why do you need to check its status anyway?
-- Show quoteHide quoteMiha Markic [MVP C#, INETA Country Leader for Slovenia] RightHand .NET consulting & development www.rthand.com Blog: http://cs.rthand.com/blogs/blog_with_righthand/ "John" <John@nospam.infovis.co.uk> wrote in message news:enIrbxZjHHA.4188@TK2MSFTNGP02.phx.gbl... > 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() > > 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 Show quoteHide quote "Miha Markic" <miha at rthand com> wrote in message news:FD6A24A0-1861-45F7-838E-3F6986707AE2@microsoft.com... > 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/ > > "John" <John@nospam.infovis.co.uk> wrote in message > news:enIrbxZjHHA.4188@TK2MSFTNGP02.phx.gbl... >> 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() >> >> > 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. -- Show quoteHide quoteMiha Markic [MVP C#, INETA Country Leader for Slovenia] RightHand .NET consulting & development www.rthand.com Blog: http://cs.rthand.com/blogs/blog_with_righthand/ "John" <John@nospam.infovis.co.uk> wrote in message news:%2388azIejHHA.5084@TK2MSFTNGP03.phx.gbl... > 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 > > "Miha Markic" <miha at rthand com> wrote in message > news:FD6A24A0-1861-45F7-838E-3F6986707AE2@microsoft.com... >> 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/ >> >> "John" <John@nospam.infovis.co.uk> wrote in message >> news:enIrbxZjHHA.4188@TK2MSFTNGP02.phx.gbl... >>> 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() >>> >>> >> > >
Talking with USB GPS in VB.Net
Is This Overkill? Designing Email Msg. Bundle csv files Output Ascii 0x02 as part of record How to create generic object at run-time? Help Converting Some C# Code to Visual Basic... Datagrid Multiple Select Versioning problem Database Connection Speed Issue. I'm stumped! |
|||||||||||||||||||||||