2009-08-18 82 views
0

我有一個網站,不時需要我對Access數據庫進行批量更新,爲了方便起見,我創建了一個包含大文本框的運行一次和刪除頁面,一個驗證碼和一個硬編碼的強密碼。當我對數據庫的本地副本運行時,我沒有任何問題,但是當我在服務器上運行它時,點擊提交後大約3秒鐘就會收到「與服務器重置的連接」。不幸的是,主機環境超出了我的範圍,所以當發生這種情況時,我無法查看任何服務器端日誌。我不知道這可能是什麼原因造成的,所以我希望你們可以看看。ASP.NET - 服務器連接重置

這段代碼有點難看,因爲我真的不在乎花很多時間在上面(有些是由另一個開發者編寫的)。無論如何,我沒有看到任何明顯的功能問題。

protected void btnRunBatch_Click(object sender, EventArgs e) 
{ 
    if (Page.IsValid) 
    { 
     ArrayList queries = GetSqlStatementArray(); 
     string results = string.Empty; 

     try 
     { 
      BatchSQLInsert(Application["DBPath"].ToString(), queries); 

      if (queries.Count > 0) 
      { 
       results = "<b>Batch Operation Completed Successfully.</b><br /><br />"; 
       results += "The following queries were executed:"; 
       results += "<ul>"; 
       foreach (string query in queries) 
       { 
        results += "<li>" + query + "</li>"; 
       } 
       results += "</ul>"; 

       this.tbxBatchStatement.Text = string.Empty; 
      } 
      else 
      { 
       results = "<b>No queries to execute.</b>"; 
      } 
     } 
     catch (Exception ex) 
     { 
      results = "<b>Execution Errors Encountered:</b><br />"; 
      results += "<ul><li>" + ex.Message + "</li></ul>"; 
     } 

     this.phResults.Controls.Add(new LiteralControl(results)); 
    } 
} 

private ArrayList GetSqlStatementArray() 
{ 
    ArrayList queries = new ArrayList(); 
    string[] lines = this.tbxBatchStatement.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); 
    string lineBuffer = string.Empty; 

    foreach (string line in lines) 
    { 
     if (lineBuffer == string.Empty) 
     { 
      if ((line.ToUpper().StartsWith("SELECT") || line.ToUpper().StartsWith("INSERT") || line.ToUpper().StartsWith("UPDATE") || line.ToUpper().StartsWith("DELETE"))) 
      { 
       if (line.EndsWith(";")) 
        queries.Add(line); 
       else 
        lineBuffer = line; 
      } 
     } 
     else 
     { 
      lineBuffer += " " + line; 
      if (line.EndsWith(";")) 
      { 
       queries.Add(lineBuffer); 
       lineBuffer = string.Empty; 
      } 
     } 
    } 
    return queries; 
} 

public static void BatchSQLInsert(string DBPath, System.Collections.ArrayList sqlArray) 
{ 
    System.Data.OleDb.OleDbCommand cmd = null; 
    System.Data.OleDb.OleDbConnection conn = null; 
    System.Data.OleDb.OleDbTransaction myTrans = null; 
    int intRecsReturned = 0; 
    int i = 0; 

    if (sqlArray.Count > 0) 
    { 
     cmd = new System.Data.OleDb.OleDbCommand(); 
     conn = GetConnection(DBPath); 
     myTrans = conn.BeginTransaction(); 

     try 
     { 
      cmd.CommandType = System.Data.CommandType.Text; 
      cmd.Connection = conn; 
      cmd.Transaction = myTrans; 
      while (i < sqlArray.Count) 
      { 
       cmd.CommandText = (string)(sqlArray[i]); 
       intRecsReturned = cmd.ExecuteNonQuery(); 
       i++; 
      } 
      myTrans.Commit(); 
      conn.Close(); 
     } 
     catch (Exception eee) 
     { 
      myTrans.Rollback(); 

      throw new Exception("BatchSQLInsert() failed-" + eee.Message + "\r\nArray-" + sqlArray.ToString()); 
     } 
     finally 
     { 
      if (conn != null) 
       conn.Dispose(); 
      if (cmd != null) 
       cmd.Dispose(); 
     } 
    } 
} 
+0

你認爲你可以張貼一些web.config設置?我想看到的httpRuntime在<配置> <的httpRuntime /> BigBlondeViking 2009-08-19 15:43:23

回答

1

聽起來過程太長時間運行,則可能需要在IIS中進行調整超時設置... :(

,我知道你不能,對不起,不是真的helpful-

+0

我想這也不過正如我在說原來的問題在3秒鐘內消​​失。這顯然遠遠小於默認的IIS超時。有些東西立即中斷它。 – 2009-08-18 22:30:19

+0

例如,PHP允許您在運行時設置超時。也許IIS也允許這樣做? – 2009-08-19 01:22:48

相關問題