The timeout period elapsed prior for asp .net C#

I had a stored procedure on SQL 2000 server to run calculation with
large amount of data. When I called this stored procedure via
System.Data.SqlClient.SqlCommand on production, i got error as: (i
tried to run the stored procedure on query analyzer, and it works well)


Timeout expired. The timeout period elapsed prior to completion of the
operation or the server is not responding.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Timeout expired.
The timeout period elapsed prior to completion of the operation or the
server is not responding.

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.


Stack Trace:


[SqlException: Timeout expired. The timeout period elapsed prior to
completion of the operation or the server is not responding.]
System.Data.SqlClient.SqlCommand.ExecuteReader(Com mandBehavior
cmdBehavior, RunBehavior. runBehavior, Boolean returnStream) +742
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +194
Research.cal_cp.DataGrid1_ItemCommand(Object source,
DataGridCommandEventArgs e)

System.Web.UI.WebControls.DataGrid.OnItemCommand(D ataGridCommandEventArgs
e) +110
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(O bject source,
EventArgs e) +68
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs
args) +26
System.Web.UI.WebControls.DataGridItem.OnBubbleEve nt(Object source,
EventArgs e) +106
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs
args) +26
System.Web.UI.WebControls.Button.OnCommand(Command EventArgs e) +121

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument) +115
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
+33
System.Web.UI.Page.ProcessRequestMain() +1292


The solution   about  the problem
Got it solved by setting command CommandTimeout to a larger number. say
120.


最近用ASP和MSSQL做了一个数据库应用,
开始一切顺利,但随着数据量的增加,
先后几次查询时出现timeout的问题.
参考Option Pack文档及社区内的文章,
现在问题都已解决(至少没又发现新的).

现把解决方法总结一下:

影响服务器产生超时的设置大致有:
1. Server.ScriptTimeout,
2. Connection对象的CommandTimeOut属性,
3. Command对象的CommandTimeOut属性,
4. IE浏览器的设置.

Server.ScriptTimeout,默认值是90秒.
要增大它,在你的asp文件中加一句,如下:
Server.ScriptTimeout=999,
将页面超时设为999秒.

最初我只设置Server.ScriptTimeout,
但仍会出现timeout错误,无论它的值设成都多大.
后在社区里看到一帖子,提到commandTimeout属性,
于是查看Option Pack文档,果然还有其他的timeout.

Connection对象和Command对象都有个CommandTimeOut属性,
默认是30秒,如果你有一个耗时的查询或数据处理,
很容易就超时了.要增大它,也很容易,创建对象后,
设置它的属性,如下:
con.CommandTimeOut = 999,
设为999秒,其中con是一Connection对象.
如设为零,将无限等待,没有这一timeout限制.

Command对象不会继承Connection的这一属性,
所以对可能超时的Command也要单独设置CommandTimeout属性.

最后IE也有个超时设置,5分钟从服务器得不到数据,也超时.
这种情况可能很少碰到,
但当我把一10多万查询的结果保存为mdb文件时,
就遇到了.(至于保存的方法,请参看精华区中的一篇帖子.)
解决方法:(原文请参照微软KB中的Q181050)
1. IE要4.01 sp1以上版本.
2. 在注册表中HKEY_CURRENT_USERSoftwareMicrosoft
WindowsCurrentVersionInternet Settings中
加一DWORD类型ReceiveTimeout,值设为比如8个9.
3. restart computer.

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/445851/viewspace-605960/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/445851/viewspace-605960/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值