我试图超越30秒将SqlDataSource的超时(好像是默认值)。我试图运行具有通过记录100,000s运行存储过程。在旺季时超时。我使用的是2003服务器上的ASP.NET 4.0和IIS 6.0。
错误信息:超时过期。在操作完成或服务器之前所经过的超时周期没有响应。
我已经试过无济于事延长超时:
< asp:SqlDataSource ID="dsTest" EnableCaching="true" CacheDuration="604800" runat="server" ConnectionString="<%$ ConnectionStrings:SuperNARIC %>" SelectCommand="selectStatus" SelectCommandType="StoredProcedure" onselecting="dsTest_Selecting" >
<SelectParameters>
< asp:ControlParameter ControlID="ddlCar" Name="CountryID" PropertyName="SelectedValue" Type="Int32" />
< /SelectParameters>
< /asp:SqlDataSource>
protected void dsTest_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
e.Command.CommandTimeout = 300;
}
任何帮助将不胜感激。
谢谢
就像提到here,这为我工作。
您可以增加超时属性这样
protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
e.Command.CommandTimeout = 0;
}
设置超时为0意味着无超时
有两种类型的超时:ConnectionTimeout和的CommandTimeout:
ConnectionTimeout确定您的应用程序将等待以建立与服务器的连接的最长时间。
的CommandTimeout:最大时间允许执行的命令。
请确保您同时设置。在命令:
command.CommandTimeout = 300;
注意:这可以在Selecting
事件中应实现您的命令是一个数据源的一部分。 e.Command.CommandTimeout = 0;
0
值意味着无限期地等待。
和连接字符串:
SqlConnectionStringBuilder cs = new SqlConnectionStringBuilder(connectionString);
cs.ConnectTimeout = 300;
要么:
<add name="MyConnectionString" connectionString="Data Source=.\SQLEXPRESS; Database=MyDB; Integrated Security=True;Pooling=True;connection timeout=30" providerName="System.Data.SqlClient" />
注:尝试在全球设置连接字符串超时,也许在你的配置文件。
超时是在连接字符串中一般设定。见http://www.connectionstrings.com/完整的例子。
你需要确保你的都和CommandTimeout
你ConnectionString
的Connect Timeout
设置以防止超时在长时间运行的存储过程。如果不设置连接超时,你会超时的存储过程完成之前,即使存储过程命令本身没有超时。
连接超时/连接超时/超时默认值 - 15秒的时间长度(秒)以等待终止尝试并产生错误之前到服务器的连接。有效值是大于或等于0且小于或等于2147483647。
string myconstr = "Data Source=(local);Initial Catalog=AdventureWorks;"
+ "Integrated Security=SSPI;Connection Timeout=30"
最大连接超时值可以尝试2147483647如下设置你的Web配置连接超时值到您的连接字符串
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=144681;Initial Catalog=Customer;Persist Security Info=True;User ID=xxxxx;Password=yyyyy" providerName="System.Data.SqlClient" />
</connectionStrings>
这是对我工作:
<script runat="server">
protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
e.Command.CommandTimeout = 0;
}
</script>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="Your Connection String"
ProviderName="Teradata.Client.Provider"
SelectCommand="A SELECT COMMAND THAT TAKES A LONG TIME"
DataSourceMode="DataSet"
onselecting="SqlDataSource1_Selecting">
还有对SQL和页面响应时间都超时。
Server.ScriptTimeout = 120;
e.Command.CommandTimeout = 120;