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

      今天在维护同步软件的时候,发现数据不能同步上传。经过查询日志文件,发现这样的错误:

    *******************2014-4-2 12:43:41*******************
    重磅过磅同步错误:超时时间已到。在操作完成之前超时时间已过或服务器未响应。
    *******************2014-4-2 12:43:41*******************
    *******************2014-4-2 12:45:21*******************
    重磅过磅同步错误:超时时间已到。在操作完成之前超时时间已过或服务器未响应。
    *******************2014-4-2 12:45:21*******************

    发生的原因:由于代码中有操作存储过程,本地数据库中操作时间太长导致客户端和数据库连接超时导致。

    代码如下:

    protected void WeightBangUpdate(object sender, EventArgs e)
    {
        this.tmWeightBang.Stop();
        if (GetCmdPingResult("172.10.12.1") == "1")
        {
            DbHelperSQL.connectionString = ConfigurationManager.AppSettings["LocalConnection"].ToString();
            object single = DbHelperSQL.GetSingle("Select Top 1 WeightBangCode From TDY_WeightBang Where (NetUpStat='0' or NetUpStat is null) order by BangTime desc");
            object obj3 = DbHelperSQL.GetSingle("Select Top 1 bangtime From TDY_WeightBang Where (NetUpStat='0' or NetUpStat is null) order by BangTime desc");
            if ((single != null) && (single.ToString() != ""))
            {
                SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@WeightBandCode", SqlDbType.VarChar, 30) };
                parameters[0].Value = single.ToString();
                try
                {
                    DataTable table = DbHelperSQL.TRunProcedure("P_SyncData_WeightBang", parameters);
                    DbHelperSQL.connectionString = ConfigurationManager.AppSettings["ServerConnection"].ToString();
                    DbHelperSQL.ExecuteSql(string.Concat(new object[] { "update dbo.TDY_WeightBang set BangTime = '", obj3, "' where WeightBangCode = '", single, "'" }));
                }
                catch (Exception exception)
                {
                    Log.log("重磅过磅同步错误:" + exception.Message.ToString());
                }
            }
        }
        this.tmWeightBang.Interval = 60000.0;
        this.tmWeightBang.Start();

    这句:DataTable table = DbHelperSQL.TRunProcedure("P_SyncData_WeightBang", parameters);

    解决方法:

    1、修改配置文件:

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

    <!--连接数据库--><connectionStrings>     <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: rgb(255, 0, 0);">Connect Timeout=500</span>;"/></connectionStrings>  

    2、修改command对象的CommandTimeout属性

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

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

    来自MSDN解释:
         httpRuntime是配置asp.net http运行时设置,以确定如何处理对asp.net应用程序的请求。
         executionTimeout:表示允许执行请求的最大时间限制,单位为秒
         maxRequestLength:指示 ASP.NET 支持的最大文件上载大小。该限制可用于防止因用户将大量文件传递到该服务器而导致的拒绝服务攻击。指定的大小以 KB 为单位。默认值为 4096 KB (4 MB)。
         useFullyQualifiedRedirectUrl:表示指示客户端重定向是否是完全限定的(采用 "http://server/path" 格式,这是某些移动控件所必需的),或者指示是否代之以将相对重定向发送到客户端。如果为 True,则所有不是完全限定的重定向都将自动转换为完全限定的格式。false 是默认选项。
         minFreeThreads:表示指定允许执行新请求的自由线程的最小数目。ASP.NET 为要求附加线程来完成其处理的请求而使指定数目的线程保持自由状态。默认值为 8。
        minLocalRequestFreeThreads:表示ASP.NET 保持的允许执行新本地请求的自由线程的最小数目。该线程数目是为从本地主机传入的请求而保留的,以防某些请求在其处理期间发出对本地主机的子请求。这避免了可能的因递归重新进入 Web 服务器而导致的死锁。
        appRequestQueueLimit:表示ASP.NET 将为应用程序排队的请求的最大数目。当没有足够的自由线程来处理请求时,将对请求进行排队。当队列超出了该设置中指定的限制时,将通过“503 - 服务器太忙”错误信息拒绝传入的请求。
        enableVersionHeader:表示指定 ASP.NET 是否应输出版本标头。Microsoft Visual Studio 2005 使用该属性来确定当前使用的 ASP.NET 版本。对于生产环境,该属性不是必需的,可以禁用。

    在代码中找到命令对象比如SqlCommand对象,给CommandTimeOut属性赋一个比较大的值。比如60 秒,SqlCommand缺省超时设定是30秒。也可以将sqlcommand的timeout属性设为0.

    备注:

    值 0 指示无限制,在 CommandTimeout 中应避免值 0,否则会无限期地等待执行命令。

    [C#] public void CreateMySqlCommand() {    SqlCommand myCommand = new SqlCommand();    myCommand.CommandTimeout = 15;    myCommand.CommandType = CommandType.Text; }

    see frame=true     SqlDataAdapter   da=   new   SqlDataAdapter();   da.SelectCommand.CommandTimeout   = 60;

  • 相关阅读:
    解决 Mac launchpad 启动台 Gitter 图标无法删除的问题
    React 与 React-Native 使用同一个 meteor 后台
    解决 React-Native mac 运行报错 error Failed to build iOS project. We ran "xcodebuild" command but it exited with error code 65. To debug build logs further, consider building your app with Xcode.app, by ope
    一行命令更新所有 npm 依赖包
    swift学习笔记
    IOS语言总结
    focusSNS学习笔记
    别小看锤子,老罗真的很认真
    windowsphone开发页面跳转到另一个dll中的页面
    【令人振奋】【转】微软潘正磊谈DevOps、Visual Studio 2013新功能、.NET未来
  • 原文地址:https://www.cnblogs.com/ypfnet/p/3640638.html
Copyright © 2011-2022 走看看