Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connection timeout in ODBC

I know that I can set the connection timeout for MS SQL Server when using ADO or OLE DB, by adding Connect Timeout=somevalue to the connection string.

This doesn't seem to work for ODBC connections though. Specifically, we made the decision to use the standard SQL Server ODBC driver that ships with Windows XP (SQLSRV32.DLL version 2000.85.1132.00) instead of the newer SQL Native Client and it is with this driver that the connection always times out on 15 seconds, irrespective of the Connect Timeout setting.

Also, when it times out, I get two errors. The first is the timeout and the second is "Invalid connection string attribute" so I guess Connect Timeout is not what I need. The final clue that I'm missing the plot, came from this somewhat dated article: http://msdn.microsoft.com/en-us/library/ms811006.aspx

Does anyone know if there is a way to specifiy the connection timeout in the connection string for the standard SQL Server ODBC driver?

like image 636
Cobus Kruger Avatar asked Feb 28 '23 12:02

Cobus Kruger


1 Answers

You can set the connection timeout by setting the SQL_ATTR_CONNECTION_TIMEOUT connection attribute with SQLSetConnectAttr.

You can set the statement query timeout by setting the SQL_ATTR_QUERY_TIMEOUT statement attribute with SQLSetStmtAttr().

like image 84
user593075 Avatar answered Mar 11 '23 10:03

user593075