我在 Visual Studio 2008 中有一个用 C# 代码编写的 asp.net Web 应用程序。
我有一个 SQL 查询,它查询另一台服务器上的 SQL Server 数据库。当我运行查询时,它会在 90 秒后超时。我尝试了各种不同的设置。
我已经搜索了互联网,但仍然找不到答案。我的代码中有一行要CommandTimeout
为查询设置。如果我将其设置为CommandTimeout = 1;
查询将在 1 秒后超时,如果我将其设置CommandTimeout = 90;
为查询将在 90 秒后超时。
这一切都很好,但我的查询大约需要。运行 150 秒。如果我将代码更改为CommandTimeout = 200;
查询仍然会在 90 秒后超时。看来我只能在小于 90 秒时更改超时。任何超过 90 秒的时间仍然会在 90 秒时超时。
这让我发疯。是否有其他设置覆盖了我的代码?
这是我的代码
// 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();
}
非常感谢期待
安迪
错误信息是:
Sys.WebForms.PageRequestManagerTimeoutException:服务器请求超时 ScriptResource.axd
代码:0