11

I'm trying to extend the timeout of an SqlDataSource beyond 30 second (Seems to be the default). I'm trying to run a stored procedure that has to run through 100,000s of records. During busy periods it times out. I'm using ASP.NET 4.0 and IIS 6.0 on 2003 server.

Error Message: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

I've tried to no avail to extend the timeout:

< 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;
    }

Any help would be greatly appreciated.

Thanks

8 Answers 8

17

Like mentioned here, this worked for me.

You can increase the Timeout property like this

protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
        {
            e.Command.CommandTimeout = 0;
        }

Setting timeout to 0 means no timeout

Sign up to request clarification or add additional context in comments.

Comments

11

There are two types of timeout: ConnectionTimeout and CommandTimeout:

ConnectionTimeout Determines the maximum time your app will wait to establish a connection to your server.

CommandTimeout: Max time allowed for a command to execute.

Make sure you set both. In the Comand:

 command.CommandTimeout = 300;

Note: This can be implemented in the Selecting event should your command be part of a DataSource. e.Command.CommandTimeout = 0; A value of 0 means to wait indefinitely.

And connection string:

SqlConnectionStringBuilder cs = new SqlConnectionStringBuilder(connectionString);
cs.ConnectTimeout = 300;

Or:

<add name="MyConnectionString" connectionString="Data Source=.\SQLEXPRESS; Database=MyDB; Integrated Security=True;Pooling=True;connection timeout=30" providerName="System.Data.SqlClient" />

Note: Try setting the connection string timeout globally, perhaps in your config file.

2 Comments

Hi, I have the following in my web.config: Connection Timeout=180
Cool, pump it up to 500 just for testing purposes and see.
3

Timeout is generally set in your connection string. See http://www.connectionstrings.com/ for complete examples.

1 Comment

Hi, I have the following in my web.config: Connection Timeout=180
2

This is what worked for me:

  <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">

Comments

1

You need to ensure both your CommandTimeout and your ConnectionString's Connect Timeout are set to prevent timing out on long-running stored procedures. If you don't set the connection timeout, you'll timeout before the stored procedure is finished, even if the stored procedure command itself hasn't timed out.

1 Comment

Thank you for the quick responses. I have the following in my web.config: Connection Timeout=180
0

Connect Timeout/Connection Timeout/Timeout Default Value - 15 sec The length of time (in seconds) to wait for a connection to the server before terminating the attempt and generating an error. Valid values are greater than or equal to 0 and less than or equal to 2147483647.

string myconstr = "Data Source=(local);Initial Catalog=AdventureWorks;"
    + "Integrated Security=SSPI;Connection Timeout=30"

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring(v=vs.100).aspx

1 Comment

Thank you for the quick responses. I have the following in my web.config: Connection Timeout=180
0

The Maximum Connection Time Out Value can be 2147483647. Try setting the Connection Timeout value into your Connection string in your Web Config as below

<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>

1 Comment

And Add <add name="MyConnectionString" connectionString="Data Source=.\SQLEXPRESS; Database=MyDB; Integrated Security=True;Pooling=True;connection timeout=30" providerName="System.Data.SqlClient" /> into the <connectionStrings></connectionStrings>
-1

There's a timeout for both the SQL and the page response time.

Server.ScriptTimeout = 120; 
e.Command.CommandTimeout = 120;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.