【问题标题】:Time out error while executing the query执行查询时出现超时错误
【发布时间】:2012-02-22 23:25:09
【问题描述】:

我正在存储过程中执行以下查询,将一年的事务从一个表转移到另一个表:

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

当我使用VB6调用存储过程时,它会超时。

我尝试将我的 RDO 连接上的 QueryTimeout 属性设置为 5 秒,如下所示:

RdoConn.QueryTimeout = 5000

但它仍然超时。

如何防止查询执行超时?

【问题讨论】:

  • 您的查询持续时间超过 5 秒,请尝试设置 timeout = 0 - 它会禁用它。

标签: sql sql-server vb6 sql-server-2000


【解决方案1】:

如果你使用 Ado 连接你可以使用下面的代码

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

然后使用此连接执行您的查询。

您的查询需要多长时间才能正常运行?

更新:
使用 RdoConnection,你可以尝试设置 LoginTimeout 事件

RdoConn.QueryTimeout = 5000
RdoConn.LoginTimeout = 5000

或如Oleg Dok指出的那样

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

【讨论】:

  • 不执行单行,耗时 30 分钟并显示超时错误,我正在使用 rdo 连接
  • 30 分钟???通过 1) 使用真实日期列和 2) 添加索引,您将获得巨大的优势。
【解决方案2】:

您的两个选项(不更改数据库架构)是:

1) 增加你的超时时间例如:

RdoConn.QueryTimeout = 30000

2) 如果您的查询执行时间超过 30 秒,那么您可能应该尝试将您的 select 语句分解为更小的部分:

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

如前所述,您还应该查看数据库中的索引和数据类型以提高性能

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-11
    • 1970-01-01
    • 2021-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-03
    • 1970-01-01
    相关资源
    最近更新 更多