zoukankan      html  css  js  c++  java
  • Timeout 时间已到。在操作完成之前超时时间已过或服务器未响应。

    近来遇到这样一个错误:Timeout 时间已到。在操作完成之前超时时间已过或服务器未响应。错误截图如下:

    错误原因分析:
    产生错误时我执行的操作需要的执行时间比较长。我测试了一下,那个操作用到的存储过程,需要处理的数据有13多万条,需要执行时间大概是1分40秒。下图是当时执行时的截图。

    而客户端与数据库连接时间以及命令的执行时间都是有限的,当这两个时间其中一个小于操作时间,错误就会产生。

    解决方法:
    第一步:修改Web.config配置文件。在数据库连接字符串中加上连接时间Connect Timeout,根据实际情况定时间。

    1. <!--连接数据库-->  
    2. <connectionStrings>  
    3.      <add name="strConnDB" connectionString=" Data Source=192.168.*.*;Initial Catalog=DatabaseName;Persist Security Info=True;User id=sa;Password=password;pooling=true;max pool size=800;min pool size=300;<span style="color:#FF0000;">Connect Timeout=500</span>;"/>  
    4. </connectionStrings>  


    第二步:修改command对象的CommandTimeout属性。 

    1. SqlCommand cmd = new SqlCommand();  
    2. cmd.CommandTimeout = 180;  

    这里设置的时间是180秒,即三分钟!可根据需要设置,如果过长,也可以设置为0,当此属性设置为0时表示不限制时间。此属性值应该慎用。

    到此为止,问题完美解决。

    补充:
    SqlCommand.CommandTimeOut:获取或设置在终止执行命令的尝试并生成错误之前的等待时间。
    SqlConnection.ConnectionTimeout:获取在尝试建立连接时终止尝试并生成错误之前所等待的时间。

  • 相关阅读:
    0593. Valid Square (M)
    0832. Flipping an Image (E)
    1026. Maximum Difference Between Node and Ancestor (M)
    0563. Binary Tree Tilt (E)
    0445. Add Two Numbers II (M)
    1283. Find the Smallest Divisor Given a Threshold (M)
    C Primer Plus note9
    C Primer Plus note8
    C Primer Plus note7
    C Primer Plus note6
  • 原文地址:https://www.cnblogs.com/zhoading/p/8601642.html
Copyright © 2011-2022 走看看