ADO Connection Timeout problem

让人想犯罪 __ 提交于 2019-12-31 03:11:14

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/5483051/ado-connection-timeout-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!