Nick Vaccaro
Nick Vaccaro

Reputation: 5504

SQL_ATTR_QUERY_TIMEOUT Not Timing Out

Setup

Using SQL Server 2008 R2.

I have an ODBC call to a stored procedure that should time out after 3 seconds by using the SQLSetStmtAttr function with the SQL_ATTR_QUERY_TIMEOUT parameter.

SQLSetStmtAttr( command, SQL_ATTR_QUERY_TIMEOUT, (SQLPOINTER)&timeOut, NULL );

Test

I set a delay in the stored procedure for 15 seconds. The stored proc does indeed take just over 15 seconds to return.

WAITFOR DELAY '00:00:15'

Issue

The problem is that the stored procedure returns correctly, where I am expecting an error.

Any ideas?

Upvotes: 2

Views: 3370

Answers (1)

Nick Vaccaro
Nick Vaccaro

Reputation: 5504

Issue discovered.

The timeOut variable (int) was passed into SQLSetStmtAttr as a reference, and the value of the reference location was much larger than 3.

Correct implementation is:

SQLSetStmtAttr( command, SQL_ATTR_QUERY_TIMEOUT, (SQLPOINTER)timeOut, NULL );

Upvotes: 4

Related Questions