我有一个网站,不时需要我对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();
}
}
}
你认为你可以张贴一些web.config设置?我想看到的httpRuntime在<配置> <的httpRuntime /> 配置> –
BigBlondeViking
2009-08-19 15:43:23