我正在实施一个AJAX服务,该服务启动长时间运行的进程并通过Javascript的setInterval获取状态。完整代码在http://blog.robseder.com/2013/10/18/executing-a-long-running-process-from-a-web-page/
AjaxServices.asmx创建了我的worker类的新静态实例。 Worker类更新其进度。问题是一切都在本地工作。但是当它部署到服务器时它会挂起并且永远不会越过线路。我使用IIS 7。
using(SqlConnection conn = new SqlConnection(string))
using(SqlCommand command = conn.CreateCommand())
{
//...
if (conn.State != System.Data.ConnectionState.Open)
conn.Open()
}
AjaxServices.asmx / GetStatus工作正常......它返回下面圈出的状态(HTTP 200)。问题是它根本没有命中我的Sql代码或try-catch块。
工人类代码摘录
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString()))
{
UpdatePercent(6, 7, "Starting (inside USING)...", runId);
#region first step
using (SqlCommand command = conn.CreateCommand())
{
command.CommandType = System.Data.CommandType.StoredProcedure;
command.CommandText = "[dbo].[sp name]";
//parameters... etc...
UpdatePercent(7, 8, "Parameters added, connection state: " + connectionState, runId);
//code doesn't proceed past this line
if (conn.State != System.Data.ConnectionState.Open)
conn.Open();
UpdatePercent(5, 10, "about to enter try-catch...", runId);
try
{
UpdatePercent(5, 10, "Starting run insertion...", runId);
command.ExecuteNonQuery();
runId = int.Parse(command.Parameters["@RunID"].Value.ToString());
UpdatePercent(10, 15, "Inserted run dimension...", runId);
}
catch(SqlException exc)
{
UpdatePercent(100, 100, exc.Message, runId);
}
}
答案 0 :(得分:1)
将上述评论中的想法转化为答案:
必须将其放入try / catch以注意引发SqlException
这是一个连接问题。
//code doesn't proceed past this line
if (conn.State != System.Data.ConnectionState.Open)
conn.Open();