链接数据库时,几个可以设置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,

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)

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.commandtimeout(v=VS.100).aspx


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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值