SQL_ATTR_QUERY_TIMEOUT Not Timing Out

我们两清 提交于 2019-12-24 11:39:10

问题


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?


回答1:


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 );


来源:https://stackoverflow.com/questions/16041991/sql-attr-query-timeout-not-timing-out

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!