Error Connecting SqlServer on Multithread Environment

Discussion of open issues, suggestions and bugs regarding usage of dbExpress drivers for SQL Server in Delphi and C++Builder
Post Reply
erik78
Posts: 23
Joined: Thu 14 Feb 2008 10:11

Error Connecting SqlServer on Multithread Environment

Post by erik78 » Mon 07 Jul 2008 15:02

Hello everybody,

I have a problem when I try to connect to sqlserver database on multithread environment.

Exactly, I get the error SQL Server Error: OLE DB error occured. Code 800401F0h CoInitialize has not been called when I change the property Connected on TSQLConnection object at TRUE.

Thanks a lot.

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

Post by Antaeus » Tue 08 Jul 2008 11:42

You should call CoInitialize for each additional thread. Also remember to call CoUnInitialize at the end of thread.

erik78
Posts: 23
Joined: Thu 14 Feb 2008 10:11

Post by erik78 » Wed 16 Jul 2008 09:06

Antaeus wrote:You should call CoInitialize for each additional thread. Also remember to call CoUnInitialize at the end of thread.
Hello everybody, this solution is correct and works good. But, I want to know if there is any way in DBExpress driver (for example by parameter) that put this code automatically when open new DBExpress connection on a new thread.

Thanks.

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

Post by Antaeus » Wed 16 Jul 2008 11:26

There is no way to do it automatically. You should call CoInitialize/CoUnInitialize manually in additional threads that use the driver.

erik78
Posts: 23
Joined: Thu 14 Feb 2008 10:11

Post by erik78 » Mon 21 Jul 2008 09:10

Antaeus wrote:There is no way to do it automatically. You should call CoInitialize/CoUnInitialize manually in additional threads that use the driver.
Hello,

In dbExpress driver for Oracle this problem dosen't exist, it's not necessary to call CoIntialize/CoUnInitialize manually, why?

In other words, You will change the of dbExpress SQL Server driver for to do this automatically or not?

In afirmative case, when(more or less)?

Thanks for your attention.

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

Post by Antaeus » Tue 22 Jul 2008 08:26

DbxSda uses OLE DB to work with SQL Server. Therefore before connecting it is necessary to initialize OLE by calling CoInitialize. In usual applications VCL does it automatically. In console applications, services, additional threads of multithreaded applications it is necessary to call CoInitialize manually. DbxSda cannot execute CoInitialize itself as it may cause unexpected problems at another parts of the program also using OLE.

Post Reply