Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C++ ADO SQL-Server-2008 , +
Hi Guys,

I have some C++ code that is working in Real-Time with a decoder. Its job is to Insert into SQL 2008 R2 and its currently using ADO 2.8 to do it.

However i dont want it to block while doing the Insert, because it holds up other packets arriving from the decoder. So i am trying to convert it to perform its calls Asynchronously so i can blindly Insert my packets which will be faster. Although depending on the speed, it is possible that i may need to Insert a 2nd packet before the 1st one had finished.

I have written some sample code in C# (ADO.NET) and proved that Async mode works, but i cannot get any sample code (ADO 2.8) to work in Async mode in C++ and it is driving me nuts!! I though that i needed to use the ExecuteComplete event but that does not fire either when in this mode?

Please would somebody help me find out what the heck i need to do make some progress on making Async work?

Many many thanks,
Posted 8-Feb-12 3:38am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I had something similar a few years ago, my program was reading from a file and inserting into a SQL database. I vaguely emember reading that asynchronous ADO required support from the underlying provider, and MS SQL Server did not provide that support.
I used separate threads: one thread was reading the input file and building INSERT commands, then it passed them to three worker threads. The communication between threads used a message queue for each worker thread, which encapsulated a std::queue exposing only synchronized versions of push(), top() and pop(). The last element in each queue was a NULL, to notify the worker thread to break the loop; this was the only common state. In fact the worker threads spent very little time waiting for locks, and more time waiting for SQL Server to complete the INSERT commands; the client thread practically didn't wait at all.
It was less work than it sounds, a couple of days at most, and I kept the multi threading infrastructure for later use.
Hope this helps,
aka_Rich at 8-Feb-12 12:02pm
Hmmm interesting...
So are you saying that the Provider may be what is holding this back? Today i did think of that, so i used the SQL Native Client 10 provider instead of the SQLOLEDB provider but i still had the same results.
What stumps me is that the MS Docs talk about the Async mode, but do not detail on how to properly process an Async command? I am forced to make assumptions.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 324
1 Maciej Los 239
2 Sergey Alexandrovich Kryukov 182
3 CPallini 120
4 Richard MacCutchan 120
0 OriginalGriff 5,474
1 Sergey Alexandrovich Kryukov 4,713
2 Peter Leow 2,944
3 DamithSL 2,465
4 Maciej Los 2,434

Advertise | Privacy | Mobile
Web01 | 2.8.140718.1 | Last Updated 8 Feb 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid