SQL Server timeout分析和总结

本文介绍了数据库连接中的传入和传出连接概念,并详细探讨了Web端访问、SSMS客户端访问及数据库实例间远程访问时的各种超时设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

wKioL1gS_qPDo2gmAADB7KEmKyI261.png


我们从数据库实例的角度出发,它会收到来自Web端的访问、用户的直接访问,它也可能同时访问其他数据库实例。那么,连接就分为传入连接(Incoming connection)访问和传出连接(Outgoing connection)访问。


首先,针对传入连接,我们来看看Web端的访问超时:有ASP.NET请求超时、WebService请求超时、IIS请求超时、数据库连接超时和查询超时。


参考:

http://www.cnblogs.com/wuya/archive/2010/08/03/1791167.html

http://www.cnblogs.com/kingboy2008/p/3711143.html

http://www.xuebuyuan.com/308400.html

http://ultrasql.blog.51cto.com/9591438/1864004


接着,针对传入连接,我们来看看用户通过SSMS访问数据库时的超时设置。


参考:

http://ultrasql.blog.51cto.com/9591438/1863961


最后,针对传出连接,我们来看看数据库跨实例远程访问的超时设置。


参考:

http://ultrasql.blog.51cto.com/9591438/1863914


SQL Server JDBC driver provides a property called `loginTimeout` that specifies the number of seconds to wait for a connection to be established before timing out. This property can be set through the JDBC URL or programmatically in your Java code. To set the `loginTimeout` property through the JDBC URL, you can append it to the end of the connection string as shown below: ``` jdbc:sqlserver://<server>:<port>;databaseName=<database>;loginTimeout=<timeout> ``` Replace `<server>` with the name or IP address of your SQL Server instance, `<port>` with the port number (default is 1433), `<database>` with the name of the database, and `<timeout>` with the number of seconds to wait for a connection to be established before timing out. Alternatively, you can set the `loginTimeout` property programmatically in your Java code as shown below: ``` String url = "jdbc:sqlserver://<server>:<port>;databaseName=<database>"; Properties props = new Properties(); props.setProperty("user", "<username>"); props.setProperty("password", "<password>"); props.setProperty("loginTimeout", "<timeout>"); Connection conn = DriverManager.getConnection(url, props); ``` Replace `<username>` and `<password>` with the credentials for connecting to the database, and `<timeout>` with the number of seconds to wait for a connection to be established before timing out. Note that the `loginTimeout` property only affects the initial connection to the database. Once the connection is established, the `queryTimeout` property can be used to set a timeout for individual SQL statements.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值