Calling a Procedure Asynchronously with the DB2.NET Data Provider

Is there a way to call a DB2 stored procedure asynchronously using the .NET .NET data provider?

+1


a source to share


4 answers


There are several ways that fit together, it will depend on your scenario.

What I was doing in Oracle was to return 1000 units of XML data from the database based on a queue of work item IDs. Getting them in one pass with the datareader didn't work, so I got them one at a time to several different threads (each thread got a work item from the queue until the queue was empty). As each individual thread got a result, it put the XML in a producer-producer queue based on Joseph Albahari's excellent threading tutorial . A separate thread looked at the consumer-producer queue, performed XSL transformations on the data, and wrote them to a file - of course I was testing single-threading first, and that was significantly slower.

I tried using threadpool / asynchronous delegates to get started (as a general advice on threading use a threadpool where possible, which delegates do as well) which might work if you don't have more than 64 items. WaitHandle.WaitAll

usually has a limit of 64 work items.
... Since I had 1000, this was not a good option, other than making them in 64 batches, which seemed kludgy.

Out of memory, I gracefully exited the producer threads when there was no more work for each of them, and then blocked until the producer queue was empty.



The most important thing is to make sure you have completely separate DB objects for each thread, otherwise you will run into thread problems.

If you just want to execute one asynchronous storage procedure in a Windows / WPF application, you might need to use a worker bean component .

Let me know if you know if you need more information.

+2


a source


BeginExecuteNonQuery not working?



+1


a source


If DB2 does not support BeginExecuteReader, you can use asynchronous delegates to do the trick. Functionally it will be the same, except that you implement it yourself rather than using something built in.

Check out an example here: Asynchronous Query SQL Query ...

+1


a source


The problem is the lack of BeginExecuteNonQuery.

0


a source







All Articles