2009-08-18 38 views
0

私は時々アクセスデータベースの一括更新が必要なウェブサイトを持っており、これを容易にするために大きなテキストボックスを含む実行時および削除ページを作成しました。キャプチャ、ハードコーディングされた強力なパスワードが含まれています。これをデータベースのローカルコピーに対して実行しても問題はありませんが、サーバーで実行すると、送信をクリックして約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

は、私は、<設定>でのhttpRuntimeをご覧になりたいですか?あなたには、いくつかのweb.configファイルの設定を投稿できると思います <のhttpRuntime /> 私もこれを考えたが、私は言ったように – BigBlondeViking

答えて

1

は、プロセスがあまりにも長時間実行されるように、あなたが時間にIISの設定をそれを調整する必要があるかもしれませんね... :(私はあなたがいないことを知って

、申し訳ありません、本当に

をhelpful-ありません
+0

元の質問それはティ約3秒で消えます。明らかに、デフォルトのIISタイムアウトよりはるかに少ないです。何かがすぐにそれを中断しています。 –

+0

PHPのように、実行時にタイムアウトを設定することができます。おそらくIISもそれを許していますか? –

関連する問題