我确实有 ASP.NET 页面,它通过 Page_Load 上的 SqlDataSource 调用存储过程并绑定(bind) GridView。在 PageLoad 上,我正在做这样的事情:
string connectionString = BLTutela.BLclsDatabaseConfigurations.GetDefaultConnectionString();
dataSource.ConnectionString = connectionString;
dataSource.SelectParameters["ReportFromDate"].DefaultValue = reportFromDateValue.Date.ToString();
...
GridView1.DataSource = dataSource;
GridView1.DataBind();
dataSource是SqlDataSource,调用StoredProcedure。 代码可以运行,但它只是第一个版本,因为可能存在以下问题(我认为这些问题可能会发生,因为它是 Report 页面会生成很长的报告):
1) 存储过程运行时间过长 -> 可能会发生 SessionTimeout 并且用户在很长一段时间内看不到系统的任何响应
2) 即使存储过程已经完成,将数据加载到gridview 中也可能是一个很长的过程。这可能会导致另一个 session 超时。
我需要一个解决方案 1) 不显示长服务器进程(存储过程)的 session 超时 2) 在 gridview 中显示数据没有超时, 3) 加载数据时显示进度条。
我从未使用过 Threads 或 AsyncCalls,所以我想先做一些调查。
现在我找到了以下链接: http://madskristensen.net/post/Asynchronous-GridView-in-5-simple-steps.aspx 我想知道这是否适用于我的情况以及我不知道哪些问题。
请您参考如下方法:
为了解决您的问题,您可以在字符串连接上定义超时
调整连接超时属性
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=;Initial Catalog=;Persist Security Info=True;User ID=;Password=;Connect Timeout=200" providerName="System.Data.SqlClient"/>
</connectionStrings>
您可以在 SqlDataSource 的 Selecting 事件中设置超时值:
protected void SqlDataSource1_Selecting(object sender,
SqlDataSourceSelectingEventArgs e)
{
e.Command.CommandTimeout = 200;
}
