Click here to Skip to main content
12,503,321 members (58,357 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C++ SQL-Server ADO , +
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,
Rich.
Posted 8-Feb-12 3:38am

1 solution

Rate this: bad
 
good
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,

Pablo.
  Permalink  
Comments
aka_Rich 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
Top Experts
Last 24hrsThis month


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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100