SqlDataSource 超时

我在继承的 VS 2010 中保留了一个 C# 应用程序,但我遇到了超时问题。


正在调用的存储过程现在需要更长的时间来执行,这会产生以下错误:


无法检索记录数据:超时已过期。在操作完成之前超时时间已过或服务器没有响应。


该SqlDataSource采用的是直接在代码中实例化,我不知道如何设置CommandTimeout属性似乎因为它没有用。这是真的?如果不是,我如何访问该属性?


我见过的解决方案SqlDataSource在.aspx文件中,通常CommandTimeout设置在控件(例如:gridview)事件中。这不是这里的情况。


编辑:


一些代码


Results = new SqlDataSource();


Results.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["EM"].ConnectionString;


Results.SelectCommandType = SqlDataSourceCommandType.Text;


Results.SelectCommand = "exec sproc";


DataView ReturnedDataSet = (DataView)Results.Select(new 

System.Web.UI.DataSourceSelectArguments());


慕田峪7331174
浏览 280回答 1
1回答

守候你守候我

尽管我强烈建议您从 SqlDataSource 移开(运行!),但您可以从 C# 设置命令超时。您可以将事件处理程序连接到一个事件,这会公开DbCommand ,您可以在其中设置 timeout。var ds = new SqlDataSource("connectionString", "select * from dbo.Project_Master");ds.Selecting += (object s, SqlDataSourceSelectingEventArgs e) => e.Command.CommandTimeout = 1000;var dataView = (DataView)ds.Select(new DataSourceSelectArguments());
打开App,查看更多内容
随时随地看视频慕课网APP