我刚刚使用了一个ASP.NET页面的Web应用程序,后面是C#。所有人都坐在SQL Server上。存储过程附带的所有数据。几乎所有过程都是动态SQL,并且根据传入的参数在过程本身中构建sql语句。
实际上有三个页面,唯一的区别是传递给SQL的参数和一些标签。该页面加载一个网格,打开时加载三个下拉列表。还有其他两个gridview,但是只有在提供更多具体信息后才会加载它们。
随着网站的公告,这些页面之一正在得到大量使用。而且有很多超时SQL超时错误。但是,如果我移到三个页面中的另一个页面,它们的执行速度很快,那么在加载数据时就不会出现明显的暂停。而且,如果我运行这些过程,那么它们都将在一秒钟之内同时运行,而页面将超时。因此,我不认为这些是由于SQL Server性能下降而导致的实际超时。
我是数据库管理员,而不是编码员,在志愿服务期间被告知要为几个俱乐部建立此站点。我一直在学习中,很多答案都来自这个站点。但是在这种情况下,我什至不知道我应该寻找什么。我在下面提供了似乎相关的信息。如果有帮助,我很乐意使用完整的.aspx和.cs更新。
页面加载很简单:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SelectedDogID.Text = "0";
SelectedTrialID.Text = "0";
SelectedHandlerID.Text = "0";
ddYear.DataBind();
ddTrial.DataBind();
ddTrial.Visible = false;
LabelTrial.Visible = false;
}
}
站点为https://trialpoints.com/,这是第一个按钮“ USBCHA Sheep”,这是每个页面都在苦苦挣扎的页面。后两个按钮几乎相同,包括使用几乎相同的数据集,但效果很好。
在我看来,我在页面上的aspx或C#上做了一些不正确的操作,因此它们无法处理多个请求(完全不能或至少很好)。 我在C#中只有一个地方称为过程,其余地方设置为aspx数据源。这段代码是:
protected void ddTrial_SelectedIndexChanged(object sender, EventArgs e)
{
SelectedTrialID.Text = ddTrial.SelectedValue;
if (SelectedTrialID.Text != "0")
{
mvPoints.ActiveViewIndex = 3;
rbTrial.Checked = true;
GridViewIndTrial.DataBind();
//Now populate the fields at the top of the form
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
SqlCommand cmd = new SqlCommand("SingleTrialReturnDetailsForPointsPage", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@Organization", SqlDbType.NVarChar, 30));
cmd.Parameters.Add(new SqlParameter("@TrialID", SqlDbType.Int, 4));
cmd.Parameters["@Organization"].Value = Convert.ToString(tbOrganization.Text);
cmd.Parameters["@TrialID"].Value = Convert.ToInt32(ddTrial.SelectedValue);
conn.Open();
using (SqlDataReader read = cmd.ExecuteReader())
// Data is accessible through the DataReader object here.
{
while (read.Read())
{
lblTrialID.Text = (read["TrialID"].ToString());
lblTrialID.Text = (read["TrialID"].ToString());
lblTrialName.Text = (read["TrialName"].ToString());
lblTrialDate.Text = (read["TrialDate"].ToString());
lblTrialYear.Text = (read["TrialYear"].ToString());
lblDogsToPost.Text = (read["DogsToPost"].ToString());
lblDogsWithPoints.Text = (read["DogsWPoints"].ToString());
GridViewIndTrial.Caption = (read["TrialName"].ToString());
}
read.Close();
}
conn.Close();
conn.Dispose();
}
else
{
GridViewIndTrial.DataSource = null;
lblTrialID.Text = Convert.ToString("");
lblTrialName.Text = Convert.ToString("");
lblTrialDate.Text = Convert.ToString("");
lblTrialYear.Text = Convert.ToString("");
lblDogsToPost.Text = Convert.ToString("");
lblDogsWithPoints.Text = Convert.ToString("");
GridViewIndTrial.Caption = Convert.ToString("");
}
}
在慢速页面上等待后的错误消息是:
[Win32Exception (0x80004005): The wait operation timed out]
[SqlException (0x80131904): Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +212
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +81
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +630
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +4222
System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +58
System.Data.SqlClient.SqlDataReader.get_MetaData() +89
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted) +437
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest) +2617
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) +1636
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +64
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +243
System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +37
System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +10
System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +138
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +134
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +84
System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1441
System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +286
System.Web.UI.WebControls.ListControl.PerformSelect() +36
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +71
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +93
System.Web.UI.WebControls.BaseDataBoundControl.set_RequiresDataBinding(Boolean value) +104
System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewChanged(Object sender, EventArgs e) +15
System.Web.UI.DataSourceView.OnDataSourceViewChanged(EventArgs e) +99
System.Web.UI.WebControls.SqlDataSourceView.SelectParametersChangedEventHandler(Object o, EventArgs e) +36
System.Web.UI.WebControls.ParameterCollection.OnParametersChanged(EventArgs e) +20
System.Web.UI.WebControls.Parameter.UpdateValue(HttpContext context, Control control) +143
System.Web.UI.WebControls.ParameterCollection.UpdateValues(HttpContext context, Control control) +102
System.Web.UI.WebControls.ParameterCollection.GetValues(HttpContext context, Control control) +37
System.Web.UI.WebControls.SqlDataSourceView.InitializeParameters(DbCommand command, ParameterCollection parameters, IDictionary exclusionList) +257
System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +579
System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +286
System.Web.UI.WebControls.ListControl.PerformSelect() +36
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +71
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +93
System.Web.UI.WebControls.ListControl.OnPreRender(EventArgs e) +23
System.Web.UI.Control.PreRenderRecursiveInternal() +166
System.Web.UI.Control.PreRenderRecursiveInternal() +236
System.Web.UI.Control.PreRenderRecursiveInternal() +236
System.Web.UI.Control.PreRenderRecursiveInternal() +236
System.Web.UI.Control.PreRenderRecursiveInternal() +236
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4720