title: Cannot set CommandTimeout to longer than 90 seconds
body: <p>I have an asp.net web app written with C# code behind in Visual Studio 2008.</p>
  
  <p>I have a SQL query that queries a SQL Server database on another server. When I run the query it times out after 90 seconds. I have tried all sorts of different settings.</p>
  
  <p>I've trawled the internet but still cannot find an answer. I have a line in my code to set <code>CommandTimeout</code> for the query. If I set it to <code>CommandTimeout = 1;</code> the query will time out after 1 second, if I set it to <code>CommandTimeout = 90;</code> the query will timeout after 90 seconds. </p>
  
  <p>This is all good but my query takes approx. 150 seconds to run. If I change the code to <code>CommandTimeout = 200;</code> the query still times out after 90 seconds. It seems I can only change the timeout when it is less than 90 seconds. Anything above 90 seconds still times out at 90 seconds.</p>
  
  <p>This is driving me mad. Is there another setting somewhere that is overriding my code?</p>
  
  <p>Here is my code</p>
  
  <pre><code>// bind the data to the Gridview
  private void BindTaskList()
  {
      string startDate = StartDate.Text;
      string endDate = EndDate.Text;
  
      // Create a connection string referring to the connection string from web.config file
      string conStr = ConfigurationManager.ConnectionStrings["Docupro_ReportingConnectionString"].ConnectionString;
  
      SqlConnection sqlConnection = new SqlConnection(conStr);
  
      // This is the SQL query and must be in one long line
      SqlCommand sqlCommand = new SqlCommand("SELECT T5.DisplayName AS 'User', T2.LongName AS 'Print Type', SUM(T1.Quantity) AS 'Total Quantity', '£'+CONVERT(varchar, SUM(T1.Amount), 3) AS 'Total Cost' FROM tblTransaction T1 JOIN tblItem T2 ON T1.ItemID = T2.ItemID JOIN tblLedger T3 ON T1.LedgerID = T3.LedgerID JOIN tblTender T4 ON T1.TenderID = T4.TenderID JOIN tblCustomer T5 ON T4.CustomerID = T5.CustomerID JOIN tblTerminal T6 on T1.TerminalID = T6.TerminalID JOIN tblStation t7 on T6.StationID = t7.StationID WHERE (TransactionDateTime BETWEEN @StartDate AND @EndDate)AND T3.LongName = 'Not Assigned' GROUP BY T5.DisplayName, T2.LongName ORDER BY T5.DisplayName", sqlConnection);
  
      // Create the parameters from the text boxes and drop down list
      sqlCommand.Parameters.Add(new SqlParameter("@StartDate", startDate));
      sqlCommand.Parameters.Add(new SqlParameter("@EndDate", endDate));
  
      // Set the command timeout to 200 seconds to allow for long queries
      sqlCommand.CommandTimeout = 200;
      sqlConnection.Open();
  
      // Create a DataSet to fill with data
      SqlDataAdapter myAdapter = new SqlDataAdapter(sqlCommand);
      DataSet myDataSet = new DataSet();
      myAdapter.Fill(myDataSet);
  
      // Turn off GridView Footer
      GridView1.ShowFooter = false;
  
      // Fill the GridView with the DataSet
      GridView1.DataSource = myDataSet;
      GridView1.DataBind();
  }
  </code></pre>
  
  <p>Many thanks in anticipation</p>
  
  <p>Andy</p>
  
  <p>Error message is:</p>
  
  <blockquote>
    <p>Sys.WebForms.PageRequestManagerTimeoutException: The server request timed out
    ScriptResource.axd<br>
    Code:0</p>
  </blockquote>