sql time out

Last post 10-08-2009 8:29 PM by kwanann. 7 replies.

Sort Posts:

  • sql time out

    10-07-2009, 4:59 PM
    • Member
      459 point Member
    • avmood
    • Member since 02-17-2008, 5:20 PM
    • Posts 844

    l have a query that I need to run.  I added Connect Timeout=0 in the web.config. However, it still times out sometimes and sometimes it doesn't.  I also tried the following as I'm getting the query from a sqldatasource, but it doesn't work. How can I fix this?


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

  • Re: sql time out

    10-07-2009, 6:08 PM
    • Contributor
      2,477 point Contributor
    • kwanann
    • Member since 02-05-2009, 7:59 AM
    • SG
    • Posts 492
    • TrustedFriends-MVPs

    when you say it doesnt work.. what exactly is the error you get?


    also, if you run this sql in mgmt studio, does it work? how long does it take?

    MVP ASP.NET C#
    View my blog @ http://jefferytay.wordpress.com
  • Re: sql time out

    10-08-2009, 9:23 AM
    • Member
      459 point Member
    • avmood
    • Member since 02-17-2008, 5:20 PM
    • Posts 844

    This is the error I'm getting

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

    Server Error in '/Reports' Application.

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

    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.Data.SqlClient.SqlException: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.



  • Re: sql time out

    10-08-2009, 9:25 AM
    • Member
      459 point Member
    • avmood
    • Member since 02-17-2008, 5:20 PM
    • Posts 844

    It works in sql server. It takes about 10-30 seconds depending on the criteria I selected. The sql itself has 3 subqueries.

  • Re: sql time out

    10-08-2009, 9:49 AM
    • Member
      459 point Member
    • avmood
    • Member since 02-17-2008, 5:20 PM
    • Posts 844

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


    <asp:GridView ID="GridViewExcel" runat="server" DataSourceID="QuerySource" emptydatatext="No data available." >
      </asp:GridView>
          <asp:sqldatasource id="QuerySource" SelectCommand="SqlDataSource1_Selecting" DataSourceMode="DataSet"
            connectionstring="<%$ ConnectionStrings:Conn %>"
            runat="server"/>


    The QuerySource I have is dynamic, so any time an user can select the criteria, and hit submit it will run it. One of the criterias is a StartDate and EndDate. The longer the date, the more data will be return. For example, if I only 2 day range, it runs fine, but if I select 200 range it time out. The interesting thing is if I run the 2 day range first and then change the date range to 200, it won't time out. So I think the e.Command.CommandTimeout = 0 is not initialized when I run the query the first time and that's why it is timing out if I start the application and run 200 date. So is there a way for me to set e.Command.CommandTimeout = 0 before it is run? Is that make sense?

  • Re: sql time out

    10-08-2009, 9:54 AM
    • Member
      459 point Member
    • avmood
    • Member since 02-17-2008, 5:20 PM
    • Posts 844

    For example in the following 3 scenarios

    scenarios 1. select a 2 day range -> runs fine


    scenarios 2. select a 200 day range -> sql time out


    scenarios 3. select a 2 day range -> runs fine

                        select a 200 day range -> runs fine

                        ....................... -> runs fine


    The only time it time out is if I start the application and run it for the 200 day range first.


  • Re: sql time out

    10-08-2009, 10:27 AM
    • Member
      459 point Member
    • avmood
    • Member since 02-17-2008, 5:20 PM
    • Posts 844

    I decided to not use the sqldatasource, and it works fine now. Thanks.

  • Re: sql time out

    10-08-2009, 8:29 PM
    • Contributor
      2,477 point Contributor
    • kwanann
    • Member since 02-05-2009, 7:59 AM
    • SG
    • Posts 492
    • TrustedFriends-MVPs

    hmm it does not make sense though, if it times out the first time, it will always time out.


    for the 200 day range, how long does it run exactly?

    MVP ASP.NET C#
    View my blog @ http://jefferytay.wordpress.com
Page 1 of 1 (8 items)