CoInitialize Error on Database Connection

Discussion of open issues, suggestions and bugs regarding usage of dbExpress drivers for SQL Server in Delphi and C++Builder
Post Reply
Posts: 1
Joined: Tue 12 Sep 2017 07:22

CoInitialize Error on Database Connection

Post by adeel.aziz » Tue 12 Sep 2017 07:53


I have been trying to integrate DevArt dbExpress component (trial version) in my Delphi 2009 application. When I do so in a separate thread it gives me the following error:
OLE DB error occurred. Code 800401F0h.
CoInitialize has not been called.
So, I added the following code in the Execute method of the thread:

Code: Select all

So, it started working. Previously I was using dbExpress version 10 that comes with Delphi (which uses OLE DB driver for SQL Server). It did not gave me this error. But when I have tried to use DevArt component (which uses SQL Server Native Client 11), the error appeared. My question is that why do I need to call CoInitialize in devArt when I do not need this in the dbExpress component.



Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: CoInitialize Error on Database Connection

Post by azyk » Tue 12 Sep 2017 13:12

If dbExpress driver uses standard OLEDB provider or SQL Server Native Client to connect to SQL Server, the CoInitialize method should be called before opening a connection. More details about this in Embarcadero documentation: ... nformation

Maybe, in a custom project with standard dbExpress driver you passed the already opened TSQLConnection instance to the thread, therefore CoInitialize/CoInitializeEx should not be called in the Execute method.

Note that Devart dbExpress driver for SQL Server has a possibility to connect in the Direct mode without using additional client libraries, i.e. there is no need to call CoInitialize/CoInitializeEx in the Direct mode. To select the Direct mode in Devart dbExpress driver for SQL Server, set the 'DevartSQLServerDirect' value to the TSQLConnection.DriverName property.

You can read more detailed description of the Direct mode in SDAC documentation:

Post Reply