【问题标题】:This page cannot be displayed error when calling a long stored procedure调用长存储过程时无法显示此页面错误
【发布时间】:2015-08-26 22:10:26
【问题描述】:

我正在使用 ASP.Net 页面调用存储过程。存储过程需要很长时间,所以我将数据库命令超时属性设置为 0,这意味着无限。我还在 web.config 中将 executionTimeout 设置为 7200,这意味着 2 小时。

当从该页面调用存储过程时,经过很长时间它会抛出错误:

此页面无法显示

我已经写了 try catch 块并设置断点,但它没有进入 catch。

我该如何解决这个问题?

编辑

Here's the code:

try
{
//database is Sybase
ConnectionOpenedHere();
AseCommand command = new AseCommand();
command.Connection = con;
command.CommandType = CommandType.StoredProcedure;
command.CommandTimeout = 0;
//some more code here
command.CommandText = storedProcedure;
command.ExecuteNonQuery();    //The code doesn't go beyond this line and shows error after a long time
}
catch (Exception ex)
{
    Response.Write(ex.Message);
}

编辑

终于能够捕捉到异常了。这是错误:

错误:与 Sybase 服务器的连接已丢失。全部活跃 事务已回滚

堆栈跟踪:在 Sybase.Data.AseClient.AseCommand.CheckResult(Int32 res) 在 Sybase.Data.AseClient.AseCommand.Execute() 在 Sybase.Data.AseClient.AseCommand.ExecuteNonQuery() 在 MyWebsite.Database.MyStoredProcedure(Int32 子类型,字符串 idno)

没有内部异常。

【问题讨论】:

  • 能否分享相关代码
  • 这很可能是浏览器放弃等待页面响应造成的。可能需要进行一些重新设计。让浏览器等待 2 小时等待响应是不合理的……
  • 问题已编辑并添加代码
  • 你的 SP 需要多长时间?
  • 至少 1 小时 30 分钟。

标签: asp.net database stored-procedures timeout


【解决方案1】:

在您的 web.config 文件中尝试以下解决方案。希望这会奏效。它将延长执行直到您的存储过程运行..

但是你的存储过程必须是完美的。

<appSettings>
 <add key="aspnet:MaxHttpCollectionKeys" value="9999" /> 
</appSettings>
<system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="1048576"/>
      </requestFiltering>
    </security>
  </system.webServer>
  <System.Web>
     <httpRuntime maxRequestLength="102400" executionTimeout="3600" requestValidationMode="2.0"/>
  </System.Web>
 <sessionState timeout="10000"/>  

并添加机器密钥

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-29
    • 1970-01-01
    • 1970-01-01
    • 2016-03-31
    • 2020-04-24
    • 1970-01-01
    相关资源
    最近更新 更多