ADO + CoInitialize in threads? Mystery...

From: Kjell Rilbe (krilbe.sp_at_mblock.home.se)
Date: 02/23/05


Date: Wed, 23 Feb 2005 18:07:50 +0100

Hi,

I have a TThread and in TThread.Execute I do this:

1. Create TADOConnection and open it (Firebird via ODBC).
2. Create TADODataSet and connect it to the TADOConnection.
3. Set CommandText and open it.
4. Read data.
5. Close TADODataSet.
6. Repeat 3-5 a couple of times.
7. TADODataSet.Free.
8. TADOConnection.Free.

It all seems to work fine, but Craig Stuntz suggested that I should call
CoInitialize/CoUninitialize because these components use COM.

In case those calls are required I should get an error "CoInitialize has
not been called" (800401F0 hex), but I dont.

So perhaps the ADO components call CoInit etc. internally?

I tested that, but they don't. I can verify that they don't by calling
CoInitialize myself and checking the return value - I always get S_OK.
If it had already been called I should get S_FALSE (or
RPC_E_CHANGED_MODE if I use the wrong threading model).

I always get S_OK. I tested before step 1, after step 8, and between
step 4 and 5. I tested with both threading models.

Any clues?

Kjell

-- 
---------------------------------------------------------------------------
Kjell Rilbe
Home: +46 8 7610734
Cell: +46 733 442464
---------------------------------------------------------------------------
"If there's a price for bein' me, that's one I'll have to pay"
Aaron Tippin
---------------------------------------------------------------------------


Relevant Pages

  • Re: ConnectionTimeout and CommandTimeout Properties
    ... Use TADODataset instead of TADOconnection. ... TADODataSet is great "swiss knife" type tool which personally I love it. ... Once I replaced the TADOconnection components with TADODataSet, ...
    (borland.public.delphi.database.ado)
  • Re: console app with data module?
    ... the culprits weren't the reporting componets. ... > delete the TADOConnection, ... > TADOTable, and TADODataset, ...
    (borland.public.delphi.non-technical)