1. 程式人生 > >連結資料庫時,幾個可以設定timeout的地方

連結資料庫時,幾個可以設定timeout的地方

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,

這裡需要注意的是,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

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.