Hello all, I am going to test later running a SQL proc call so it runs asynch as the operation on the SQL side takes up to 30 minutes to complete and return. I want to just call it and continue the code run on my web page. I have pasted my code. The PrepareCommand is just putting together the parameters I pass in a param array etc. so there is not need to post that with the code below I think. My questions are:
- How will the EndAsyncOperation get called when it is done or do I need some more code like a while loop and thread sleep to handle the end of the call? I don't want a loop again because I don't want to wait for it I think. I put together examples I found but nothing was totally clear.
- I did not know how to close the connection so is it okay to have the connection.close where I have it?
- Do I need a command timeout at all due to it may take 30 minutes and I don't want to error at all. I assume no if it is asynch it will be fine.
Thanks for any help.
public void AsynchBeginExecuteNonQuery(SqlConnection conn, CommandType commandType, string commandText, SqlParameter commandParameters)
if (conn == null) throw new ArgumentNullException("connection");
// open the connection here because of asynch
SqlConnection connection = new SqlConnection(conn + "async=true;");
// Create a command and prepare it for execution
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, conn, (SqlTransaction)null, commandType, commandText, commandParameters);
AsyncCallback callback = new AsyncCallback(EndAsyncOperation);
catch (Exception e)
csLog.LogMsg("\r\n\r\nDAController:AsynchBeginExecuteNonQuery( " + e.Source + "\r\n\r\n" + e.Message + "\r\n\r\n" + e.StackTrace);
void EndAsyncOperation(IAsyncResult ar)
SqlCommand cmdAsyn = (SqlCommand)ar.AsyncState;
//End the asynchronous call