I am looking for a way to let my C# (4.0) app send data to a SQL Server 2008 instance, asynchronously. I kind of like what I saw at http://nayyeri.net/asynchronous-command-execution-in-net-2-0 but that is not quite what I am looking for.
I have code like this:
// myDataTable is a .NET DataTable object
SqlCommand sc= new SqlCommand("dbo.ExtBegin", conn);
SqlParameter param1 = sc.Parameters.AddWithValue("@param1", "a");
SqlParameter param2 = sc.Parameters.AddWithValue("@param2", "b");
SqlParameter param3 = sc.Parameters.AddWithValue("@param3", myDataTable);
param3.SqlDbType = SqlDbType.Structured;
param3.TypeName = "dbo.MyTableType";
int execState = sc.ExecuteNonQuery();
And because the myDataTable is potentially large, I don’t want the console app to hang while it sends the data to the server, if there are 6 big loads I want them all going at the same time without blocking at the console app. I don’t want to send serially.
All ideas appreciated, thanks!
AsynchronousProcessingproperty on the connection string to True.BeginExecuteNonQueryBut what is
dbo.ExtBegindoing? It all depends on it, as the calls may well serialize on locks in the database (at best) or, at worst, you may get incorrect results if the procedure is not properly designed for concurency.