When to call OLE Co(Un)Initialize for MSConnection ?

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Petya
Posts: 21
Joined: Wed 28 Jul 2010 11:24

When to call OLE Co(Un)Initialize for MSConnection ?

Post by Petya » Tue 24 Apr 2012 09:05

Hello folks,

SDAC help for MSConnection.Connect says :
"Note, if you would like to use SDAC in service, console or just at a separate thread, you need to call CoInitialize for each thread. Also remember to call CoUnInitialize at the end of a thread."
I have 2 pcs. of MSConnection put on the main form statically, 1 another created and freed runtime in the main thread, and 5 more created in 5 other threads that can quasi randomly exist or not during normal operation.

Today I noticed that neither of the 3 MsConnections in the main thread calls CoInitialize before connecting.
Should I leave it this way ?
Or call it once at program startup in the main thread ?
Or call it once before connecting each instance of MSConnection ?

Thanks, Peter

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Wed 25 Apr 2012 09:29

Hello,

When using TMSConnection in the main stream, the main Windows message queue is used, so, for functioning of such TMSConnection's, there is no need to call the Colnitialize method. When creating TMSConnection in streams separate from the main one, it is necessary to call the Colnitialize method explicitly for providing this stream with a synchronizing messages queue. You can find more details on using COM objects in MSDN

Petya
Posts: 21
Joined: Wed 28 Jul 2010 11:24

Okay

Post by Petya » Wed 25 Apr 2012 09:39

Thanks AlexP,

I suppose you meant threads instead of streams.

Cheers, Peter

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Wed 25 Apr 2012 10:11

hello,

Yes your are right, "streams" meant "threads"

Post Reply