ADO连接超时问题

发布于 2024-10-28 03:44:23 字数 208 浏览 4 评论 0原文

使用 TADOConnection 类连接到 SQL Server 2005 db。

有 ConnectionTimeOut := 5; // 秒。

尝试同步打开连接。

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

是否需要设置任何属性或方法来影响此行为?

Using TADOConnection class to connect to SQL server 2005 db.

Having ConnectionTimeOut := 5; // seconds.

Trying to open the connection synchronously.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

源来凯始玺欢你 2024-11-04 03:44:24

不,设置 ConnectionTimeout 属性就足够了

我遇到了确切的问题(D2009,MSSQL2005),但是TADOConnection.ConnectionTimeout 对我来说效果很好(顺便说一句,默认值此属性为 15 秒)。请注意,超时分散度相当大,因此一旦您会在 5 秒后超时,甚至在 10 秒后超时,但 20 秒对于连接尝试来说确实太多了。

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

如果您确实在查询执行方面遇到问题,而不仅仅是连接尝试方面出现问题,这篇文章可能会对您有所帮助
ADO 组件 CommandTimeout

No, it's enough to set the ConnectionTimeout property

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.

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.

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

小兔几 2024-11-04 03:44:24

TADOConnection.ConnectionTimeout - 连接到数据源的超时(以毫秒为单位)
执行命令的超时(以毫秒为单位) ,增加 ConnectionTimeout 属性的值,否则,如果在执行某些查询时遇到错误, - 增加 CommandTimeout 属性的值。

TADOConnection.CommandTimeout -如果在尝试连接时遇到超时错误,则

TADOConnection.ConnectionTimeout - Timeout in milliseconds to connect to data source
TADOConnection.CommandTimeout - Timeout in milliseconds to execute command

if you getting timeout error on trying to connect, increase value of ConnectionTimeout property, else if you getting an error on executing some query, - increase value of CommandTimeout property.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文