确定在线程中使用TADOConnection [英] Ok to use TADOConnection in threads

查看:287
本文介绍了确定在线程中使用TADOConnection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个TCPip服务器应用程序。该应用程序有一个全局TADOConnection。这个全局ado连接用于主线程查询,也用于线程进程。



这样可以吗? ADOConnection是否内置了同时处理多个查询的机制?



我的应用程序在测试环境中可以找到(2-5个连接)。但是,在生产环境中部署的TADOQuery链接到ADOConnection的设置已经被设置为打开了无法解释的访问冲突。我应该使用ADOConnection或者所有的查询都是自己连接到数据库(这可能要花费更多的资源)?

解决方案

每个线程都需要有自己的连接对象。以下链接提供了更多信息: http://delphi.about.com/od/ kbthread / a / query_threading.htm



文章中的一些要点:



1]在使用任何dbgo对象之前,必须手动调用CoInitialize和CoUninitialize。 CoInitialize失败将导致CoInitialize未被调用异常。 CoInitialize方法初始化当前线程上的COM库。 ADO是COM。



2]你不能使用主线程(应用程序)中的TADOConnection对象。每个线程都需要创建自己的数据库连接。


I have created an TCPip server application. The application has one global TADOConnection. This global ado connection is used both for main thread queries and also within threaded processes.

Is this ok? Does the ADOConnection have built in mechanisms to handle multiple queries at the same time?

My application works find in testing environments (2-5 connections). But deployed in a production environment I am getting "unexplainable" access violations at the point the TADOQuery linked to the ADOConnection are set to opened.

Should I be using ADOConnection or should all queries just make the connection to the database on their own (which is probably a bit more resource costly)?

解决方案

Each thread needs to have its own connection object. The following link provides more information: http://delphi.about.com/od/kbthread/a/query_threading.htm

Some key points from the article:

1] CoInitialize and CoUninitialize must be called manually before using any of the dbGo objects. Failing to call CoInitialize will result in the "CoInitialize was not called" exception. The CoInitialize method initializes the COM library on the current thread. ADO is COM.

2] You cannot use the TADOConnection object from the main thread (application). Every thread needs to create its own database connection.

这篇关于确定在线程中使用TADOConnection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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