簡體   English   中英

ASP.NET C#等待操作超時

[英]ASP.NET C# The Wait Operation Timed Out

遇到使我的整個網站崩潰的錯誤。 等待操作正在超時,我已閱讀了using {}塊的文檔,但無法理解為什么會發生這種情況。 任何幫助表示贊賞。

[Win32Exception (0x80004005): The wait operation timed out]

我最近正在處理的頁面是itemediting.aspx:

  <%@ Page Language="C#" AutoEventWireup="true" CodeFile="itemediting.aspx.cs" Inherits="admin_itemediting" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>elmtree - Admin</title>      
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" />

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="../styles/mylist.css" />

</head>
<body>
    <form id="form1" runat="server">

        <img src="images/ELleft.png" style="width:226px; height:52px; margin-top: 3px; margin-left: 17px; text-align: justify; float: none;"/></a></li>

<div class="container">
    <h1> Item Edit </h1> </div>    
        <div class="container">    
            <div class="form-group">    
                <label class="col-sm-2 control-label">Item name: </label>     
                <div class="col-md-4">
                    <asp:TextBox ID="itemnametext" runat="server" Text="" CssClass="form-control">    
                    </asp:TextBox>
                </div>
                <div class="pull-right">
                    <asp:Button CssClass="btn btn-primary btn-lg" ID="updatebutton" role="button" runat="server" Text="save" OnClick="updatebutton_Click" />
                </div>
            </div>    
        </div>               
        </form>
    </body>
    </html>

背后的代碼:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;    
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;    

public partial class admin_itemediting : System.Web.UI.Page{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int row = 0;
            if (Request.QueryString["itemID"] != null)
            {    
                row = int.Parse(Request.QueryString["itemID"]);
            }
            else
            {
                Response.Redirect("itemedit.aspx");
            }    
        }

        string connectionString = WebConfigurationManager.ConnectionStrings
            ["ConnectionString"].ConnectionString;

        SqlConnection myConnection = new SqlConnection(connectionString);    
        myConnection.Open();    
        string query = "SELECT * FROM reports WHERE ID=@rowid";        
        SqlCommand myCommand = new SqlCommand(query, myConnection);    
        myCommand.Parameters.AddWithValue("@rowid", row);    
        SqlDataReader rdr = myCommand.ExecuteReader();

        while (rdr.Read())
        {
            string myname = rdr["itemname"].ToString();    
            itemnametext.Text = myname;
        }
    }

    protected void updatebutton_Click(object sender, EventArgs e){

        string connectionString = WebConfigurationManager.ConnectionStrings ["ConnectionString"].ConnectionString;    
        SqlConnection myConnection = new SqlConnection(connectionString);    
        myConnection.Open();    
        string itemnametextupdate = itemnametext.Text;    
        string query = "UPDATE reports SET itemname = @itemnewname";        
        SqlCommand myCommand = new SqlCommand(query, myConnection);     
        myCommand.Parameters.AddWithValue("@itemnewname", itemnametextupdate);    
        myCommand.ExecuteNonQuery();    
        myConnection.Close();    
        Response.Redirect("updateimage.aspx");    
    }

    public object row { get; set; }
}

只是一個建議。

if (!IsPostBack)
        {
            int row = 0;
            if (Request.QueryString["itemID"] != null)
            {    
                row = int.Parse(Request.QueryString["itemID"]);
            }
            else
            {
                // here even if you make redirect the code continue to run
                // and you do not know whats going on then... a call to db and a redirect.
                Response.Redirect("itemedit.aspx");
                // so here add a return;
                return;
            }    
        }

下一個可能的錯誤是,回發時該row未保存在viewstate上,而是采用默認值。 使您的row變量為:

int cRow
{
    set
    {
        ViewState["cRow"] = value;
    }
    get
    {
        if (ViewState["cRow"] != null)
            return Convert.ToInt32(ViewState["cRow"]);
        else
            return -1;
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM