ADO components CommandTimeout

后端 未结 3 1568
后悔当初
后悔当初 2021-01-12 13:26

I have a problem with settings of the query execution timeout with TADOQuery, TADOCommand or TADODataSet (I\'ve tried it with each one). I have a tiny application, which con

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-12 13:54

    CommandTimeout is kicking in when you have long running queries. There is a CommandTimeout property of TADOConnection but that does not work. You have to use the CommandTimeout of the TADODataSet instead.

    If the server is unavailable, your question says "connection is lost", you need to specify ConnectionTimeout of the TADOConnection component. Default is 15 seconds before control is returned to your application.

    Edit 1 I think I have discovered a situation where CommandTimeout does not work. I have tested this against a really big table. It takes several minutes to return all rows. If my stored procedure does select * from BigTable the query timeout never happens. At least I was not patient enough to wait it out. But if the query looks like this select * from BigTable order by Col1 and there is no index on Col1, the CommandTimout works as expected.

    The difference between the two queries is obvious when running them in SSMS. The first starts to immediately return rows and the second needs to "think" about it before it returns rows. When SQL Server have found the rows it needs and start to return them, CommandTimeout does not work.

    If you set CursorLocation to clUseServer the CommandTimeout will work as expected for both queries.

提交回复
热议问题