Skip to Content.
Sympa Menu

freetds - [freetds] Detecting dead TCP connection

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Andrew Victor" <avictor.za AT gmail.com>
  • To: freetds AT lists.ibiblio.org
  • Subject: [freetds] Detecting dead TCP connection
  • Date: Wed, 6 Aug 2008 20:45:09 +0200

hi,

Is there a way to easily /quickly detect if an MS-SQL server has
closed the TCP connection, or the connection is dead?

Our application maintains a pool of open database connections, and
when it gets a request we needs to execute a database stored-procedure
on one of those connections.
We use the ctlib interface, so we call ct_command(), ct_param() and
then ct_send().
But only after the ct_send() step do we get any error: "Write to the
server failed".

Looking at the FreeTDS source, the TCP connection may be marked as
"closed" at the OS level but since FreeTDS hasn't subsequently
performed any operations (read/write/etc) on the socket it does not
know the TCP connection is closed.
It's only when ct_send() tries to send a message, does the OS indicate
the socket has been closed.

Using the TCP KeepAlive mechanism also only informs the OS level
earlier, not FreeTDS or the application.


1. Is there a command that can be used to check the real state
(alive/dead) of the TCP connection?
2. Is there a way that the Client Message Callback could be triggered
earlier? ie, when the OS detects the connection was closed.
3. Is there a way to auto-reconnect and automatically re-execute the command?


Regards,
Andrew Victor



  • [freetds] Detecting dead TCP connection, Andrew Victor, 08/06/2008

Archive powered by MHonArc 2.6.24.

Top of Page