0

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

}

Volearix
  • 1,573
  • 3
  • 23
  • 49
  • Tried the answer here -> http://stackoverflow.com/questions/3829202/iis-request-timeout-on-long-asp-net-operation?answertab=votes#tab-top ? – Armen Abrami Dec 02 '13 at 13:50
  • Your code seems like it could have tons of improvements to make it much, much faster. Even if you give higher timeouts, the browser will time out anyway if you don't send any data in some time, and if you're sending an excel file, you can't even send any keep-alive data, so you're looking at something very complicated. Do some optimization before changing the request timeout. For example, you're opening a new connection in every step, calling the procedure again (and if you're exporting excel, you even call it with the same parameters twice)... – Luaan Dec 02 '13 at 13:51
  • @Luann The connection can easily be modified to only be created once, however, this is not the issues as it was initially like that. The operation being performed is lengthy in general and not capable of being modified [SearchNumbers] AND only accepts one number at a time, therefore has to be called for every step. The code optimization isn't really my main concern as even with the barebones call by itself, when 30,000+ numbers are provided it still errors out. – Volearix Dec 02 '13 at 14:02
  • Where/how are you receiving the timeout error? Can you show us the exact message? I ask because it's not clear to me if your browser is throwing this error trying to access your web page or if the error is coming from the (server-side?) code above getting an ADO.Net/SQL Server time out trying to execute the SQL Server command(s). It makes a big difference in how to resolve it. – RBarryYoung Dec 02 '13 at 14:50
  • @RBarryYoung Sure, error added to the question. – Volearix Dec 02 '13 at 15:11

1 Answers1

1

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.

OnoSendai
  • 3,960
  • 2
  • 22
  • 46