等待操作超时-延长超时时间

本文关键字:超时 时间 操作 等待 | 更新日期: 2023-09-27 18:12:52

我有一个网格视图,填充在一个按钮点击事件:

    <asp:GridView CssClass="hoursGrid" ID="hoursReportGridView" runat="server" AutoGenerateColumns="False" BackColor="#DEBA84" BorderColor="#DEBA84"
        BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2" DataSourceID="SqlDataSource2" OnRowDataBound="hoursReportGridView_OnRowDataBound" DataKeyNames="DifferentUsers, DoubleBookedFlag, PointPerson, Person">
        <Columns>
            <asp:BoundField DataField="Person" HeaderText="Person" SortExpression="Project" />
            <asp:BoundField DataField="Project" HeaderText="Project" SortExpression="Project" />
            <asp:BoundField DataField="ProjectType" HeaderText="Project Type" ReadOnly="True" SortExpression="Sprint" ItemStyle-HorizontalAlign="Center" />
            <asp:BoundField DataField="Theme" HeaderText="Theme" ReadOnly="True" SortExpression="Theme" ItemStyle-HorizontalAlign="Center" />
            <asp:BoundField DataField="StoryNumber" HeaderText="Story Number" SortExpression="Story" ItemStyle-Width="6%" ItemStyle-HorizontalAlign="Center" />
            <asp:BoundField DataField="StoryTitle" HeaderText="Story Title" SortExpression="Story" ItemStyle-Width="20%" />
            <asp:BoundField DataField="Effort" HeaderText="Effort" SortExpression="Effort" ItemStyle-HorizontalAlign="Right" />
            <asp:BoundField DataField="Task" HeaderText="Task" SortExpression="Task"  ItemStyle-Width="20%" HtmlEncode="false" />
            <asp:BoundField DataField="OriginalEstimateHours" HeaderText="Original Estimate" SortExpression="OriginalEstimateHours" ItemStyle-HorizontalAlign="Right" />
            <asp:BoundField DataField="Monday" HeaderText="Mon" ReadOnly="True" SortExpression="Monday" ItemStyle-HorizontalAlign="Right" />
            <asp:BoundField DataField="Tuesday" HeaderText="Tues" ReadOnly="True" SortExpression="Tuesday" ItemStyle-HorizontalAlign="Right" />
            <asp:BoundField DataField="Wednesday" HeaderText="Wed" ReadOnly="True" SortExpression="Wednesday" ItemStyle-HorizontalAlign="Right" />
            <asp:BoundField DataField="Thursday" HeaderText="Thurs" ReadOnly="True" SortExpression="Thursday" ItemStyle-HorizontalAlign="Right" />
            <asp:BoundField DataField="Friday" HeaderText="Fri" ReadOnly="True" SortExpression="Friday" ItemStyle-HorizontalAlign="Right" />
            <asp:BoundField DataField="Saturday" HeaderText="Sat" ReadOnly="True" SortExpression="Saturday" ItemStyle-HorizontalAlign="Right" />
            <asp:BoundField DataField="Sunday" HeaderText="Sun" ReadOnly="True" SortExpression="Sunday" ItemStyle-HorizontalAlign="Right" />
            <asp:TemplateField HeaderText="Total" ItemStyle-HorizontalAlign="Right">
            <ItemTemplate>
                 <asp:LinkButton ID="taskLinkButton" Text='<%# Eval("Total") %>' Enabled='<%# Eval("StoryTitle").ToString() != "" %>' runat="server" OnClick="taskLinkButton_Click" />
            </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
c#:

private void generateReport()
{
    //set sql parameters
    SqlDataSource2.SelectParameters["userParam"].DefaultValue = currentEntity;
    SqlDataSource2.SelectParameters["startDateParam"].DefaultValue = startingDay.ToString();
    SqlDataSource2.SelectParameters["endDateParam"].DefaultValue = endingDay.ToString();
    SqlDataSource2.SelectParameters["orgTeamPK"].DefaultValue = orgTeam;
    SqlDataSource2.SelectParameters["productId"].DefaultValue = productId;
    SqlDataSource2.SelectParameters["theme"].DefaultValue = themeSelected;
    hoursReportGridView.DataBind();
}

该查询在SSMS中可能需要45秒,并导致网站崩溃:

等待操作超时

描述:在执行过程中发生未处理的异常当前的web请求。请查看堆栈跟踪了解更多信息有关错误及其在代码中的起源的信息。

异常详细信息:System.ComponentModel。Win32Exception:等待操作超时

在创建一个更有效的查询之前,是否有可能使超时时间更长,以便程序不会崩溃?

等待操作超时-延长超时时间

您可以增加CommandTimeout属性。添加SqlDataSourceOnSelecting事件处理程序,并在后面的代码中添加以下内容:

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