OLE DB Error. CoInitialize has not been called

Discussion of open issues, suggestions and bugs regarding usage of dbExpress drivers for SQL Server in Delphi and C++Builder
Post Reply
Ricardo

OLE DB Error. CoInitialize has not been called

Post by Ricardo » Fri 24 Jun 2005 21:22

Hi,

I'm testing MS SQL dbExpress driver (dbexpsda.dll V2.50.5 trial). But when my Delphi7 application try to open a TSQLConnection it launch an exception: Ole DB error ocurred. Code 800401F0h. CoInitialize has not been called.

This application don't have this problem with Borland MSSQL driver.

thanks,
Ricardo

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Mon 27 Jun 2005 06:25

If you would like to use DbxSda in service, console or just at separate thread you need call CoInitialize for each thread. Also remember to call CoUnInitialize at the end of thread.

shaunwallace
Posts: 7
Joined: Sat 08 Jul 2006 06:03
Location: Durban, South Africa

Post by shaunwallace » Sat 08 Jul 2006 06:15

I have a data access module that is created per user in a user object.

In the before connect event on a dbxpress connection I call CoInitialize, is this the correct place to be doing the call OR should the call be done in each thread accessing the user object?

Also curious to find out why the core lab driver has this requirement compared to the built in borland one?

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Mon 10 Jul 2006 13:35

> In the before connect event on a dbxpress connection I call
> CoInitialize, is this the correct place to be doing the call OR
> should the call be done in each thread accessing the user object?
CoInitialize must be called one time in each thread that connects to the server. Putting CoInitialize in OnBeforeConnect event may lead to multiple calling of this function, but this shouldn't cause any problems. But you should take care about calling CoUnInitialize. It must be called only once before terminating the thread.

> Also curious to find out why the core lab driver has this
> requirement compared to the built in borland one?
Core Lab's driver uses OleDB mechanism to access MS SQL Server. We use this low-level mechanism because it has high-performance and is very good documented. This mechanism differs from Borland's one. That's why Core Lab driver for dbExpress requires a call to CoInitialize.

Guest

Post by Guest » Tue 11 Jul 2006 07:27

I keep a counter for each time I call the Initialise and then call the UniInitialiase that many times when my DataModule is destroyed. I think I read somewhere that each Initialise needs an UnInitialise.

Would that be ok? I don't think any items would still have a connection at that point in time?

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Wed 12 Jul 2006 12:52

At first CoInitialize checks if COM library is already initialised. If it's true, than second call will be ignored. But CoUnInitialize doesn't perform similar checking. So it's not important how many times you call CoInitialize, finally you have to call CoUnInitialize only once.

Guest

Post by Guest » Tue 18 Jul 2006 14:41

I found a more elegant solution as the whole problem originated from using Intraweb, I rather get Intraweb to initialise com for me. This sorts it out nicely.

When using your MS SQL DbExpress driver or ADO driver with Intraweb, you must set the ComInitialization property in the ServerController to ‘ciMultiThreaded’.

This will eliminates the "CoInitialize has not been called" error.

Post Reply