ADO 2.8在C ++中异步工作 [英] ADO 2.8 working Asynchronously in C++

查看:69
本文介绍了ADO 2.8在C ++中异步工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一些在解码器中实时工作的C ++代码.它的工作是将其插入SQL 2008 R2,并且当前使用ADO 2.8进行操作.

但是我不希望它在执行插入操作时阻塞,因为它可以容纳来自解码器的其他数据包.所以我试图将其转换为异步执行其调用,以便我可以盲目插入我的数据包,这将更快.尽管取决于速度,但我可能需要在第一个数据包完成之前插入第二个数据包.

我已经在C#(ADO.NET)中编写了一些示例代码,并证明了异步模式有效,但是我无法在C ++中以异步模式获得任何示例代码(ADO 2.8),这真让我发疯!我虽然需要使用ExecuteComplete事件,但是在此模式下也不会触发?

请有人帮我找出我需要做些什么来使异步工作取得一些进展吗?

非常感谢,
Rich.

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.

推荐答案

几年前,我的程序与此类似,我的程序是从文件读取并插入SQL数据库.我模糊地成员读到异步ADO需要底层提供程序的支持,而MS SQL Server没有提供该支持.

我使用了单独的线程:一个线程正在读取输入文件并构建 INSERT 命令,然后将它们传递给三个工作线程.线程之间的通信为每个工作线程使用一个消息队列,该消息队列封装了一个std :: queue,仅公开了 push(),top()pop()的同步版本.每个队列中的最后一个元素为NULL,以通知工作线程中断循环.这是唯一的共同状态.实际上,工作线程花很少的时间等待锁,而花更多的时间等待SQL Server完成INSERT命令.客户端线程几乎根本没有等待.

它的工作量比听起来少,最多只有几天,而且我保留了多线程基础结构以备后用.

希望这会有所帮助,

巴勃罗.
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.


这篇关于ADO 2.8在C ++中异步工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆