0

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!

4 Answers 4

2

But what is dbo.ExtBegin doing? 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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks I think you just gave me the right combination of words to websearch for. I will also look at the DB side to see if it can actually handly concurrent calls in its receiving sproc. Service Broker is out because of the additional server config overhead. I didn't want to add custom threading code, I think BeginExecuteNonQuery might do it for me. Thanks.
0

Create a thread and execute the query within that thread, make sure not to have subsequent database calls that would cause race conditions.

Comments

0

My first thought would be to spawn a new thread for the inserts, and have the main thread check the spawned thread's execution with AutoResetEvent, TimerCallback, and Timer objects.

I do it in Silverlight all the time.

Comments

0

Take a look at using Service Broker Activation. This will allow you to call a stored proc and have it run on it's own thread why you continue on the current thread.

Here is an excellent article that goes over how to do this.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.