Time out error while executing the query

霸气de小男生 提交于 2020-01-05 07:55:51

问题


I am executing the following query in a stored procedure, transferring one year's transactions from one table to another:

insert into 
    table2 
select
    * 
from 
    table1 
where 
    dates between '20110101' and 20111231'

When I use VB6 to call the stored procedure, it times out.

I've tried to set the QueryTimeout property on my RDO Connection to five seconds like so:

RdoConn.QueryTimeout = 5000

But it's still timing out.

How can I prevent the execution of the query from timing out?


回答1:


If you use an Ado connection you can use the following code

dim myConn 
Set myConn = CreateObject("ADODB.Connection") 
myConn.CommandTimeout = 3600
myConn.ConnectionTimeout = 3600

and then use this connection to execute your query.

How much time does your query take to run without issue?

Update:
Using RdoConnection, you can try to set event the LoginTimeout

RdoConn.QueryTimeout = 5000
RdoConn.LoginTimeout = 5000

or as pointed out by Oleg Dok

RdoConn.QueryTimeout = 0 'disable timeout
RdoConn.LoginTimeout = 0 'disable timeout



回答2:


Your two options (without changing the database schema) are:

1) Increase your timeout time eg:

RdoConn.QueryTimeout = 30000

2) If your query is taking longer than 30 seconds to execute then you should probably try breaking down your select statement into smaller parts:

Insert into table2 select * from table1 where dates between '20110101' and 20110131'
Insert into table2 select * from table1 where dates between '20110201' and 20110228'

As mentioned though you should also look at indexes and data types in your database to improve performance



来源:https://stackoverflow.com/questions/9076216/time-out-error-while-executing-the-query

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