Request timing out on large operation?

5.8k views Asked by At

Trying to complete a web process, however, I am receiving a 'request time out' error. I'm not sure what I can do to get around this.

I modified the method to create a new connection for every number being passed in the for loop, but it seems to be yielding the same result.

I am more of a desktop developer, not overly versed in ASP.Net, so any light that could be shed on my issue would be great.

I've looked up info on ASP background workers, which doesn't seem to be a great way to go, and I've increased the server settings to allow a higher timeout, but still timeout if a huge number of parts are provided.

I'm also trying to avoid a separate process that is scheduled on the server to execute a submitted list of numbers. If more info is needed to make sense of this, just let me know.

Also, when I attempt to run the application locally (debug) there are never issues, only when it's placed on the live site.

Here is the exact error received:

Server Error in '/' Application.

Request timed out.

Description: An unhandled exception occurred during the execution of the current web     request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Web.HttpException: Request timed out.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[HttpException (0x80004005): Request timed out.]

And here is the code:

protected void btnSearch_Click(object sender, EventArgs e)
{
// Clear our reporting panel.
panelHolder.Controls.Clear();

// Store each line in a new array item.
string[] searchlines = txtboxSearch.Text.Replace("\n", "|").Split('|');

// Create a table row containing our main table headers.
panelHolder.Controls.Add(new LiteralControl("<table style=\"width:100%;\">" +
                                                      "   <tr> " +
                                                      "      <td></td> " +
                                                      "      <td>Number</td> " +
                                                      "      <td>Comparison</td> " +
                                                      "   </tr>"));

// Variable to hold the row counts.
int j = 0;

// Store our current web members name for use in our tracking data.
string MemberName = Member.GetCurrentMember().Text;

// This table will be used solely for storing our excel exported data.
System.Data.DataTable dt = new System.Data.DataTable();

// Locate our part comparison results for every line of data supplied by our users.
for (int i = 0; i < searchlines.Count(); i++)
{
    using (SqlConnection con = new SqlConnection(dbConnection))
    {
        // If this array item is not blank we will need to collect information about it.
        if (searchlines[i].Trim() != string.Empty)
        {
            // Determine if data collection (reporting) is turned on.
            Boolean isReporting = DataCollection();
            using (SqlDataReader dr = Connect.ExecuteReader("SelectNumbers]", con,
                                                            new SqlParameter("@Number", searchlines[i].Trim()),
                                                            new SqlParameter("@CurrentMember", MemberName),
                                                            new SqlParameter("@DataCollection", isReporting)))
            {
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        // Add our table rows containing our returned data set.
                        panelCompetitorHolder.Controls.Add(new LiteralControl("<tr><td>" + Convert.ToString(i + 1) + "</td>"));
                        AddTableData(dr, "Part Number");
                        AddTableData(dr, "Comparison");

                        // Go to our next line item.
                        j += 1;
                    }
                }
            }
        }
    }
}

// Add our table to  the panel control.
panelHolder.Controls.Add(new LiteralControl("</table>"));

}

1

There are 1 answers

3
OnoSendai On

Your issue may lie in the fact that IIS assumes a maximum period of time for a given request to be processed. By default, the value is 90 seconds. Here's a few ways you can set a different amount of time:

Via Web.config - Check/add this entry on your web.config file:

<system.web>
    <httpRuntime executionTimeout="N" />
</system.web>

Programatically - You may add this to your server-side code:

Server.ScriptTimeout = N;

Where N is, in both options, the desired amount of seconds for the request timeout.

Additionally, your values may be superseded/ignored if there's an entry present at the server's applicationhost.config or machine.config files, as described here:

http://www.iis.net/configreference/system.applicationhost/sites/sitedefaults/limits

If that's the case you may have to alter the corresponding entries - or, in lieu of that, alter your codebehind content.