2016-05-08 10 views
0

Erhalte einen Fehler, der meine gesamte Website abgestürzt ist. Die Warteoperation läuft ab, ich habe die Dokumentation zur Verwendung von {} Blöcken gelesen, kann aber nicht verstehen, warum dies geschieht. Jede Hilfe wird geschätzt.ASP.NET C# Der Wartevorgang hat eine Zeitüberschreitung

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

Die Seite i zuletzt gearbeitet haben ist 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> 

-Code Behind:

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 [email protected]";   
     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; } 
} 
+1

Auf welcher Aussage hat es Timeout? –

+0

Ehrlich gesagt habe ich keine Ahnung, die Seite funktionierte gut, bis ich versuchte, das Update functionanlity hinzuzufügen. es zeigt, dass die 'row' in myCommand.Parameters.AddWithValue ("@ rowid", row); liefert einen Fehler. – Cmc9

+0

Setzen Sie einen Haltepunkt auf 'myCommand.Parameters.AddWithValue (" @ rowid ", row);' und prüfen Sie, ob die Zeile einen Wert hat. oder 'Debug.WriteLine (row);' –

Antwort

0

Nur ein Vorschlag.

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; 
      }  
     } 

nächster möglicher Fehler ist, dass die row auf Post zurück nicht auf Ansichtszustand gespeichert wird, und einen Standardwert übernehmen. Machen Sie Ihre row Variable wie folgt:

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