1.Configuring (Server Configuration Options - remote query timeout )( but Not Recommended)
The remote query timeout option specifies how long, in seconds, a remote operation can take before SQL Server times out. The default value for this option is 600, which allows a 10-minute wait. This value applies to an outgoing connection initiated by the Database Engine as a remote query. This value has no effect on queries received by the Database Engine. To disable the time-out, set the value to 0. A query will wait until it is canceled.
For more information see below Urls,
http://technet.microsoft.com/en-us/library/ms189040.aspx
http://technet.microsoft.com/en-us/library/ms189631.aspx
这里需要注意的是,remote query timeout只针对linked server有效。下面对remote query timeout的解释中说明了,remote query timeout通过设置 SQL Server Native Client OLE DB provider rowset properties中的DBPROP_COMMANDTIMEOUT起效,而 SQL Server Native Client OLE DB provider的作用就是“By using the SQL Server Native Client OLE DB Provider, SQL Server distributed queries can query data in remote instances of SQL Server.”。
http://technet.microsoft.com/en-us/library/ms177457(v=sql.105).aspx
因此,对于SQL server database engine而言,是没有timeout这个概念的,query会一直运行下去,除非客户端cancel。而也只有client端可以限制timeout。remote query timeout的作用原理是provider的超时的概念,一旦超时,provider便cancel query。
下面的方法也是通过在链接字符串中规定timeout。
2.In web config connection string you can specify Connection Timeout argument .(This setting for the entire application who access this connection
Connect Timeout -or- Connection Timeout | The length of time (in seconds) to wait for a connection to the server before terminating the attempt and generating an error. |
For more information see below URL
http://www.connectionstrings.com/articles/show/all-sql-server-connection-string-keywords
3.You can change the command time out property for particilar command. in front end coding.(This is for particular command or depends on architecture design of the application)
4. 对于SQL Server backup而言,也是会timeout的。
If a backup operation overlaps with a file-management or shrink operation, a conflict arises. Regardless of which of the conflicting operation began first, the second operation waits for the lock set by the first operation to time out (the time-out period is controlled by a session timeout setting). If the lock is released during the time-out period, the second operation continues. If the lock times out, the second operation fails.