How does the ODBC-ODBC Bridge client support connection timeouts?
Applications set connection timeouts by calling SQLSetConnectAttr with the attribute SQL_ATTR_CONNECTION_TIMEOUT
. The Easysoft ODBC-ODBC Bridge version 1.0.0.23 only uses the connection timeout when actually connecting to the server and not for all ODBC calls. If the connection doesn't succeed within the timeout period you set, you'll get a diagnostic like this:
08001:1:4:[Easysoft ODBC (Client)]Client unable to establish connection HY000:2:4:[Easysoft ODBC (Client)]Connection attempt timed out
However, there are some important points:
- Connection timeouts are not supported in Windows or multi-threaded versions of the ODBC-ODBC Bridge 1.0.0.23 client for UNIX and Linux.
- ODBC-ODBC Bridge classes the connection phase as obtaining the IP address of the server machine and connecting to it. This means that if you specify the server machine as a name rather than an IP address with the
ServerPort
attribute, your system resolver library will be used. (This may involve reading/etc/hosts
or doing a DNS query.) On some operating systems,gethostbyname()
, the call used to resolve a machine name into an IP address, cannot be interrupted and the connection timeout will not work. If this is a problem for you, specify the server machine as an IP address or tell your resolver library to consult/etc/hosts
before DNS. Then add an entry to/etc/hosts
. - The ODBC-ODBC Bridge client passes the
SQL_ATTR_CONNECTION_TIMEOUT
to the target ODBC driver. - Connection timeouts at the network level are not usable because many operating systems hard-wire them.
- If you're writing your own ODBC-ODBC client application in an environment where network connections may be dropped, you can put
alarm()
andSIGALRM
handlers (orsigsetjmp
) around your ODBC calls to implement connection timeouts.