[freetds] Connection life

Robert Klemme shortcutter at googlemail.com
Thu Nov 24 03:04:59 EST 2005


2005/11/24, martin A. <acevedoma at hotmail.com>:
> Hello, I have a question about connection and disconnection. How can I
> detect if a network connection is dead using db-lib? I have seen that there
> is a function called  dbdead, but this function does not check  if the
> network socket is alive ( I use  MS Sql Server), it never connects to the
> server... I need this because I have a connection pooling and I havte to
> detect connections dead to reconnect if it is needed, I keep the connection
> without calling a dbclose for a long time. But if the dbdead does not check
> the socket the result of calling dbdead is not reliable.
> How can I solve this problem?

This is a general problem with DB connections: you'll actually have to
execute something using this connection (for example "select 1 from
dual where 1 = 0").  But even if you do this, there's no guarantee
that the connection will be ok the next second when you send your real
command. In short there's no safe way to ensure that a connection is
ok the moment you need it. What we do is to check connections that we
draw from a pool in order to not hand out connections that we know are
stale.

HTH

Kind regards

robert


More information about the FreeTDS mailing list