2016-05-08 190 views
1

嘗試在我的網站上打開一個網頁而不是整個網頁時出現錯誤。下面是我一直在研究的兩個頁面。他們已準備好允許管理員編輯網站上的項目。真的需要幫助。 堆棧跟蹤:等待操作超時ASP.NET

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

[SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 0 - The wait operation timed out.)] 
    System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +6568558 
    System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +717 
    System.Data.SqlClient.TdsParser.ConsumePreLoginHandshake(Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean& marsCapable) +1730 
    System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover) +693 
    System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) +219 
    System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) +6597311 
    System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) +6597891 
    System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData) +942 
    System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +1162 
    System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +72 
    System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +6601145 
    System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +103 
    System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +2102 
    System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +116 
    System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +1079 
    System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +6605639 
    System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +233 
    System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +278 
    System.Data.SqlClient.SqlConnection.Open() +239 
    System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +292 
    System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +420 
    System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +277 
    System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +3326091 
    System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +28 
    System.Web.UI.WebControls.DataBoundControl.PerformSelect() +313 
    System.Web.UI.WebControls.ListView.PerformSelect() +124 
    System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +146 
    System.Web.UI.WebControls.ListView.CreateChildControls() +80 
    System.Web.UI.Control.EnsureChildControls() +189 
    System.Web.UI.Control.PreRenderRecursiveInternal() +60 
    System.Web.UI.Control.PreRenderRecursiveInternal() +222 
    System.Web.UI.Control.PreRenderRecursiveInternal() +222 
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4297 

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> 

itemediting.aspx.cs:

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

您需要包裝的SqlConnection和其他任何實現'在[使用塊] IDisposable'接口(https://msdn.microsoft。 com/en-us/library/yh598w02.aspx),或者確保將其放置在finally塊中。 – mason

+0

任何你可以提供一些代碼作爲提示?即時通訊非常新的asp.net + C#。謝謝 – Cmc9

+1

爲什麼不閱讀我之前評論中鏈接到的文檔? – mason

回答

1

正如@mason提到的,你必須確保你打電話Dispose()當你與實施IDisposable的東西完成。

更改你的代碼處理SqlConnectionSqlCommandSqlDataReader

string query = "SELECT * FROM reports WHERE [email protected]"; 

using (SqlConnection myConnection = new SqlConnection(connectionString)) 
using (SqlCommand myCommand = new SqlCommand(query, myConnection)) 
{ 
    myCommand.Parameters.AddWithValue("@rowid", row);  
    myConnection.Open(); 

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