asp.net c#SqlDataSource timout问题
我正在尝试将SqlDataSource的超时延长超过30秒(似乎是默认值)。 我正在尝试运行一个必须运行100,000个记录的存储过程。 在繁忙时期,它会超时。 我在2003服务器上使用ASP.NET 4.0和IIS 6.0。
错误消息:超时已过期。 操作完成之前经过的超时时间或服务器没有响应。
我试图延长超时无效:
< asp:SqlDataSource ID="dsTest" EnableCaching="true" CacheDuration="604800" runat="server" ConnectionString="" SelectCommand="selectStatus" SelectCommandType="StoredProcedure" onselecting="dsTest_Selecting" > protected void dsTest_Selecting(object sender, SqlDataSourceSelectingEventArgs e) { e.Command.CommandTimeout = 300; }
任何帮助将不胜感激。
谢谢
就像这里提到的,这对我有用。
您可以像这样增加Timeout属性
protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e) { e.Command.CommandTimeout = 0; }
将timeout设置为0表示没有超时
有两种类型的超时: ConnectionTimeout和CommandTimeout :
ConnectionTimeout确定应用程序等待与服务器建立连接的最长时间。
CommandTimeout :命令执行所允许的最长时间。
确保你设置两者。 在Comand中 :
command.CommandTimeout = 300;
注意:如果您的命令是DataSource的一部分,则可以在Selecting
事件中实现。 e.Command.CommandTimeout = 0;
值0
表示无限期等待。
和连接字符串 :
SqlConnectionStringBuilder cs = new SqlConnectionStringBuilder(connectionString); cs.ConnectTimeout = 300;
要么:
注意 :尝试全局设置连接字符串超时,可能在配置文件中。
超时通常在连接字符串中设置。 有关完整示例,请访问http://www.connectionstrings.com/ 。
您需要确保设置CommandTimeout
和ConnectionString
的Connect Timeout
,以防止长时间运行的存储过程Connect Timeout
。 如果未设置连接超时,则在存储过程完成之前将超时,即使存储过程命令本身未超时也是如此。
连接超时/连接超时/超时默认值 – 15秒在终止尝试并生成错误之前等待连接到服务器的时间长度(以秒为单位)。 有效值大于或等于0且小于或等于2147483647。
string myconstr = "Data Source=(local);Initial Catalog=AdventureWorks;" + "Integrated Security=SSPI;Connection Timeout=30"
最大连接超时值可以是2147483647.尝试将连接超时值设置为Web配置中的连接字符串,如下所示
SQL和页面响应时间都超时。
Server.ScriptTimeout = 120; e.Command.CommandTimeout = 120;