Reputation: 5557
I'm implementing an AJAX service that kicks off long-running process and gets the status via Javascript's setInterval. The full code is here http://blog.robseder.com/2013/10/18/executing-a-long-running-process-from-a-web-page/
AjaxServices.asmx creates a new static instance of my worker class. Worker class updates its progress. The problem is everything is working as it should locally. But it hangs and never proceeds past the line when deployed to server. I'm using 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 works fine... It returns the status circled below (HTTP 200). The problem is it doesn't hit my Sql code, or the try-catch block at all.
Worker Class code excerpt
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);
}
}
Upvotes: 1
Views: 54
Reputation: 11910
Putting the ideas from the comments above into an answer here:
This had to be put into a try/catch to notice the SqlException
being thrown that was a connection issue.
//code doesn't proceed past this line
if (conn.State != System.Data.ConnectionState.Open)
conn.Open();
Upvotes: 1