Checking db connection open status

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John

    #1

    Checking db connection open status

    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.OleDbConn ection
    Dim St As String = My.Settings.Loc alDBConnectionS tring

    LocalConn = New OleDb.OleDbConn ection(St)
    LocalConn.Open( )


  • rowe_newsgroups

    #2
    Re: Checking db connection open status

    On May 3, 12:01 pm, "John" <J...@nospam.in fovis.co.ukwrot e:
    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.OleDbConn ection
    Dim St As String = My.Settings.Loc alDBConnectionS tring
    >
    LocalConn = New OleDb.OleDbConn ection(St)
    LocalConn.Open( )
    Check the connection's State property.

    Thanks,

    Seth Rowe

    Comment

    • Patrice

      #3
      Re: Checking db connection open status

      Try :
      http://msdn2.microsoft.com/en-us/lib...te(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.in fovis.co.uka écrit dans le message de news:
      enIrbxZjHHA.418 8@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.OleDbConn ection
      Dim St As String = My.Settings.Loc alDBConnectionS tring
      >
      LocalConn = New OleDb.OleDbConn ection(St)
      LocalConn.Open( )
      >
      >

      Comment

      • William \(Bill\) Vaughn

        #4
        Re: Checking db connection open status

        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
        Welcome to the home of William Vaughn's Imagination, creations, and advice.

        Welcome to the home of William Vaughn's Imagination, creations, and advice.

        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.in fovis.co.ukwrot e in message
        news:enIrbxZjHH A.4188@TK2MSFTN GP02.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.OleDbConn ection
        Dim St As String = My.Settings.Loc alDBConnectionS tring
        >
        LocalConn = New OleDb.OleDbConn ection(St)
        LocalConn.Open( )
        >
        >

        Comment

        • Miha Markic

          #5
          Re: Checking db connection open status

          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.in fovis.co.ukwrot e in message
          news:enIrbxZjHH A.4188@TK2MSFTN GP02.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.OleDbConn ection
          Dim St As String = My.Settings.Loc alDBConnectionS tring
          >
          LocalConn = New OleDb.OleDbConn ection(St)
          LocalConn.Open( )
          >
          >

          Comment

          • John

            #6
            Re: Checking db connection open status

            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 comwrote in message
            news:FD6A24A0-1861-45F7-838E-3F6986707AE2@mi crosoft.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.in fovis.co.ukwrot e in message
            news:enIrbxZjHH A.4188@TK2MSFTN GP02.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.OleDbConn ection
            >Dim St As String = My.Settings.Loc alDBConnectionS tring
            >>
            >LocalConn = New OleDb.OleDbConn ection(St)
            >LocalConn.Open ()
            >>
            >>
            >

            Comment

            • Miha Markic

              #7
              Re: Checking db connection open status

              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/

              "John" <John@nospam.in fovis.co.ukwrot e in message
              news:%2388azIej HHA.5084@TK2MSF TNGP03.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 comwrote in message
              news:FD6A24A0-1861-45F7-838E-3F6986707AE2@mi crosoft.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.in fovis.co.ukwrot e in message
              >news:enIrbxZjH HA.4188@TK2MSFT NGP02.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.OleDbConn ection
              >>Dim St As String = My.Settings.Loc alDBConnectionS tring
              >>>
              >>LocalConn = New OleDb.OleDbConn ection(St)
              >>LocalConn.Ope n()
              >>>
              >>>
              >>
              >
              >

              Comment

              • dbahooker@hotmail.com

                #8
                Re: Checking db connection open status

                sorry kid

                ..NET 'automagically closes connections for you'


                I think that this is the biggest load of crap ever.
                we can no longer use @@SPID as a database unique identifier

                just because MS wanted to shove their premise (that keeping
                connections closed is a good thing) down our throats

                I call that EGOCENTRISM

                in ADO Classic we can either share a connection or leave it open.

                ADO.net is a failure because it has less funcitonality than ADO
                Classic






                On May 3, 9:01 am, "John" <J...@nospam.in fovis.co.ukwrot e:
                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.OleDbConn ection
                Dim St As String = My.Settings.Loc alDBConnectionS tring
                >
                LocalConn = New OleDb.OleDbConn ection(St)
                LocalConn.Open( )

                Comment

                • dbahooker@hotmail.com

                  #9
                  Re: Checking db connection open status

                  Bill

                  that is a load of crap and it is a bug

                  stfu and make microsoft fix it
                  in ADO classic we could either leave a connecetion open; or we could
                  close it-- we could share it with other users-- things were peachy

                  ADO.net is crap
                  you can't have multiple data readers on the same connection;
                  screw .NET




                  On May 3, 10:59 am, "William \(Bill\) Vaughn"
                  <billvaRemoveT. ..@betav.comwro te:
                  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 Speakerwww.beta v.com/blog/billvawww.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.
                  _______________ _______________ ____
                  Visitwww.hitchh ikerguides.nett o 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" <J...@nospam.in fovis.co.ukwrot e in message
                  >
                  news:enIrbxZjHH A.4188@TK2MSFTN GP02.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.OleDbConn ection
                  Dim St As String = My.Settings.Loc alDBConnectionS tring
                  >
                  LocalConn = New OleDb.OleDbConn ection(St)
                  LocalConn.Open( )- Hide quoted text -
                  >
                  - Show quoted text -

                  Comment

                  Working...