Question: A client is sending a query to a SQL Server . After 30 seconds a message appears on the SQL Server trace:
User error message : The statement has been terminated
If I run the code from SSMS, it completes successfully. Could you explain how I can fix this problem?
Answer: SQL Server runs queries with no timeout. The query timeout error is occurring on the client side. When a command exceeds the timeout duration, the client API sends an attention signal to SQL Server to cancel the executing query.
An example is the CommandTimeout property, defaulting to 30 seconds in ADO and ADO.NET.
If you have the Attention event added to the SQL Server trace, you’ll notice it appearing. In addition, the client API throws the timeout expired exception error message. You could recreate the message by executing the code from SSMS and hitting the cancel after 30 seconds