Good to use TADOConnection in streams

I created a TCPip server application. The application has one global TADOConnection. This global ado connection is used for both mainstream requests and threading processes.

This is normal? Does ADOConnection create mechanisms to handle multiple requests at once?

My applications work in test environments (2-5 connections). But when deployed in a production environment, I get "inexplicable" access violations at the point where the TADOQuery associated with ADOConnection is set to open.

Should I use ADOConnection or will all queries just make a connection to the database on their own (which is likely to be a more expensive resource)?

+6
delphi adoconnection
source share
2 answers

Each thread must have its own connection object. The following link contains additional information: http://delphi.about.com/od/kbthread/a/query_threading.htm

Some key points of the article:

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

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

+8
source share

@M Schenkel, see this question Is Delphis TADOConnection safe? . Each thread needs its own connection because ADO is a COM based technology and uses threaded objects.

see this sample

procedure TMyThread.Execute; begin CoInitialize(nil); try try // create a connection here except end; finally CoUnInitialize; end; end; 
+7
source share

All Articles