Chris Reeves | 15 Aug 18:25
Favicon

Setting ODBC timeouts

Hi all,

I have been trying to set login and connection timeouts using the tdsodbc
driver, without too much success. After reading many of the threads regarding
timeouts (particularly the one around January 2007) I upgraded from 0.63-3.2
(Debian etch package) to 0.82-4 (Debian lenny package). The code in question
works correctly when there is no interruption in the connection, but I am
currently testing cases where there is an interruption.

I set the SQL_ATTR_LOGIN_TIMEOUT and SQL_ATTR_CONNECTION_TIMEOUT attributes
using SQLSetConnectAttr and later calls to SQLGetConnectAttr suggest that
these attributes have indeed been changed. Despite this, no matter what I set
these two attributes to, the login always takes 40 seconds to time out and the
connection timeout appears to be 'infinite'. The timeouts in
/etc/freetds/freetds.conf are both set to 1. The code I'm using runs along the
following lines (but with additional error checking included - all calls
return SQL_SUCCESS).

/// Begin code excerpt

SQLUINTEGER currTimeout = 0;
SQLGetConnectAttr(connHandle, SQL_ATTR_LOGIN_TIMEOUT, &currTimeout, 0, NULL);
std::cout << "Current login timeout is: " << currTimeout << std::endl;
SQLGetConnectAttr(connHandle, SQL_ATTR_CONNECTION_TIMEOUT, &currTimeout, 0,
NULL);
std::cout << "Current connect timeout is: " << currTimeout << std::endl;

SQLUINTEGER timeout = 30;
SQLSetConnectAttr(connHandle, SQL_ATTR_LOGIN_TIMEOUT, (void*)timeout, 0);
SQLGetConnectAttr(connHandle, SQL_ATTR_LOGIN_TIMEOUT, &currTimeout, 0, NULL);
std::cout << "Current login timeout is: " << currTimeout << std::endl;

SQLConnect(connHandle, DSN, SQL_NTS, user, SQL_NTS, pass, SQL_NTS);

SQLSetConnectAttr(connHandle, SQL_ATTR_CONNECTION_TIMEOUT, (void*)timeout, 0);
SQLGetConnectAttr(connHandle, SQL_ATTR_CONNECTION_TIMEOUT, &currTimeout, 0,
NULL);
std::cout << "Current connect timeout is: " << currTimeout << std::endl;

/// End code excerpt

/// Begin sample output

Current login timeout is: 15
Current connect timeout is: 0
Current login timeout is: 10
Current connect timeout is: 10

/// End sample output

Based upon the mailing list threads, I had expected the timeouts in the latest 
version of freetds to correspond to those set - if not directly, then as some
multiple of these. Can anyone suggest what I may be doing wrong here?

Thanks in advance for your help,
    Chris

Gmane