Aim: Calling a very slow stored procedure (with
parameters) asynchronously from code behind of an asp.net web page
via single function call, and then forgetting about it.
Notes: I tried using
SqlCommand.BeginExecuteNonQuery
without calling
SqlCommand.EndExecuteNonQuery
(see the code below),
but the stored procedure didn’t run. (I used a tiny stored
procedure to update single field on a table for testing but the
field was not updated. It gets update when I use
SqlCommand.ExecuteNonQuery
).
私はストアドプロシージャがいつ終了するのか興味がなく、わからない。 (したがって、
SqlCommand.EndExecuteNonQuery
の呼び出しが完了するまで待つことはできません)。
Situation: After some research, I found out
that sql jobs can be used for this purpose. And for the sp
parameters; I can store them in a table and then sp can read them.
However I don’t know if this is the right approach to my problem (I
am new to SQL world). I hope you can comment on usage of an sql job
for this purpose, or suggest alternatives. Thanks.
コード:
using (SqlConnection connection = new SqlConnection(
@"Data Source=XXXMSSQL2008R2;Initial Catalog=YYY;Integrated Security=True"
+ ";Asynchronous Processing=true"))
{
connection.Open();
SqlCommand cmd = new SqlCommand("spTestProcedure", connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@pText", DateTime.Now.ToString()));
cmd.BeginExecuteNonQuery(); //Doesn't work.
//cmd.ExecuteNonQuery();//This works.
}
私はあなたが単に別のスレッドであなたのspを実行すべきだと思います。
http://msdn.microsoft.com/en-us/library
/system.componentmodel.backgroundworker.aspx