DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4
  1. #1
    Arunkumar Guest

    Connection isClosed.


    What is the best way to know if a connection, is still alive or not.
    The method isClosed seems to be irreliable.


  2. #2
    Bjarki Holm Guest

    Re: Connection isClosed.


    Hello Arunkmar,

    the isClosed() method returns whether a specified Connection has been closed
    or not. Possibly, as you mention, individual implementations might not identify
    a "corrupt" connection (one that has for some reason lost its physical database
    connection) as being "closed". Therefore, to ensure that a connection is
    valid, you might want to implement a method that actually validates a connection,
    by having it perform a simple task, such as creating a Statement.

    Obviously, this process might incur overhead if performed each time a connection
    is used. If you are using connection pooling (which I assume you are), a
    good way is to let the connection pool manage a monitor thread, that regularly
    checks on the connections in the pool, and discards corrupt connection (closes
    them, that is).

    Let me know if this did any help!

    Cheers,

    Bjarki

    "Arunkumar" <arunc@aztec.soft.net> wrote:
    >
    >What is the best way to know if a connection, is still alive or not.
    >The method isClosed seems to be irreliable.
    >



  3. #3
    Arunkumar Guest

    Re: Connection isClosed.


    Hi Bjarki,
    Thanks for ur reply.
    What we have done is, we are trying to execute a select count(*) from A_DUMMY_TABLE
    (with no rows) and if this fails, then we are resetting the
    connection.
    Think this will have minimal performance issues.
    Any comments.

    Thanks
    Arunkumar



    "Bjarki Holm" <holm@vyre.com> wrote:
    >
    >Hello Arunkmar,
    >
    >the isClosed() method returns whether a specified Connection has been closed
    >or not. Possibly, as you mention, individual implementations might not identify
    >a "corrupt" connection (one that has for some reason lost its physical database
    >connection) as being "closed". Therefore, to ensure that a connection is
    >valid, you might want to implement a method that actually validates a connection,
    >by having it perform a simple task, such as creating a Statement.
    >
    >Obviously, this process might incur overhead if performed each time a connection
    >is used. If you are using connection pooling (which I assume you are), a
    >good way is to let the connection pool manage a monitor thread, that regularly
    >checks on the connections in the pool, and discards corrupt connection (closes
    >them, that is).
    >
    >Let me know if this did any help!
    >
    >Cheers,
    >
    >Bjarki
    >
    >"Arunkumar" <arunc@aztec.soft.net> wrote:
    >>
    >>What is the best way to know if a connection, is still alive or not.
    >>The method isClosed seems to be irreliable.
    >>

    >



  4. #4
    Bjarki Holm Guest

    Re: Connection isClosed.


    Arunkmar,

    it should be enough to test whether the connection can produce a Statement
    object. This might incur overhead, if done each time a connection is used,
    although that will always depend on the type of system you are developing.
    In a Web scenario, for example, I would not recommend this for each connection
    that is used, but in a more simple scenario, where the number of concurrent
    users is more limited, that might be acceptable.

    - Bjarki

Similar Threads

  1. VB doesn't wait until SQL-query has finished
    By Daniel Teufert in forum VB Classic
    Replies: 2
    Last Post: 04-24-2002, 02:34 PM
  2. MSDE/NT Connection problem across domains
    By Will Rickards in forum Database
    Replies: 1
    Last Post: 04-06-2001, 03:50 PM
  3. Blocking problem with DSN-less connection
    By Adam Dawes in forum VB Classic
    Replies: 3
    Last Post: 12-21-2000, 11:50 AM
  4. Replies: 1
    Last Post: 10-24-2000, 04:48 PM
  5. Connection Questions...............
    By markos in forum VB Classic
    Replies: 0
    Last Post: 04-03-2000, 12:20 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links