【发布时间】: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