ADO连接超时问题 [英] ADO Connection Timeout problem

查看:166
本文介绍了ADO连接超时问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用TADOConnection类连接到SQL Server 2005数据库。

Using TADOConnection class to connect to SQL server 2005 db.

具有ConnectionTimeOut:= 5; //秒。

Having ConnectionTimeOut := 5; // seconds.

尝试同步打开连接。

服务器可用且正在运行时,连接超时工作正常。如果服务器不可用或网络连接丢失,则尝试打开连接会等待5秒以上(可能是20秒)。

When the server is available and running, the connection time out works fine. If the server is not available or network connection is lost, then attempting to open a connection waits for more than 5 seconds (may be 20 secs).

是否有任何属性或需要设置影响这种行为的方法?

Is there any property or method that needs to be set to influence this behavior?

推荐答案

否,设置ConnectionTimeout属性足够了

我遇到了确切的问题(D2009,MSSQL2005),但是 TADOConnection.ConnectionTimeout对我来说很好(顺便说一句,该属性的默认值是15秒)。请注意,超时分散范围很广,因此一旦您在5秒钟后超时,例如10秒后,但是20秒对于连接尝试来说实在是太多了。

I've had the exact problem (D2009, MSSQL2005), but TADOConnection.ConnectionTimeout works fine for me (btw. the deafult value for this property is 15 seconds). Note, that the timeout dispersion is quite wide, so once you'll be timed out after 5 seconds and later on e.g. after 10 seconds, but 20 seconds is really too much for the connection attempt.

可能您的CommandTimeout出现了问题(如果您尝试使用关联的命令执行查询ADO数据集组件)。您需要记住,如果您在数据集组件中设置TADOConnection.ConnectionTimeout:= 5,例如TADOQuery.CommandTimeout:= 15,并且您尝试执行查询,那么20秒后就会超时。

Probably you have a problem with CommandTimeout (if you are trying to execute a query with the associated ADO data set component). You need to remember, that if you set TADOConnection.ConnectionTimeout := 5 and in your data set component e.g. TADOQuery.CommandTimeout := 15, and you're trying to execute query, then you will get timeout after 20 seconds.

如果您确实对查询执行有疑问,不只是连接尝试,这篇文章还可以帮助您
ADO组件CommandTimeout

If you really have a problem with query execution, not only connection attempt, this post may help you ADO components CommandTimeout

这篇关于ADO连接超时问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆