[freetds] Can't reconnect, why?

Péter András Felvégi petschy at gmail.com
Tue May 15 10:45:56 EDT 2007


Hello,

the link on the support page
(http://www.freetds.org/userguide/help.html) is broken, but hopefully
I can provide the necessary information anyway.

Scenario: I connect to an mssql server successfully. Then, after some
time the connection breaks because of the ISP: read/write errors
(20004/20006). I detect this event, disconnect, then try to reconnect.
The reconnect always fails, no matter how long I try. If I kill the
process, and start my app again, the connect succeeds immediately. I
don't use connection pooling, so I'm a bit confused here. Is there
some internal pooling in the tds lib? Otherwise, the reconnect should
succeed in the same process, right?

I connect like this:

Connect(...)
{
	Disconnect();
	LOGINREC* loginrec = dblogin();
	DBSETLPWD(loginrec, pass_);
	DBSETLUSER(loginrec, user_);
	DBSETLAPP(loginrec, app_);
	DBPROCESS* proc = dbopen(loginrec, const_cast<char*>(server_));
	dbloginfree(loginrec);
	if (!proc) {
                  // error
	}
	// OK ...
}

Disconnect()
{
	if (m_connection) {
		dbclose(m_connection);
		m_connection = 0;
	}
}

When the query fails with read/write error, I call Reconnect() which
just calls Connect() in a loop and sleeps a bit between the retries.

I'm using FreeTDS v0.63, on Debian Etch.

my freetds.conf is:

[xxx]
        host = xxx.hu
        port = 5041
        tds version = 8.0
        client charset = UTF-8


What's the catch here?

Regards, Peter


More information about the FreeTDS mailing list