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.
Error Connecting SqlServer on Multithread Environment
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.Antaeus wrote:You should call CoInitialize for each additional thread. Also remember to call CoUnInitialize at the end of thread.
Thanks.
Hello,Antaeus wrote:There is no way to do it automatically. You should call CoInitialize/CoUnInitialize manually in additional threads that use the driver.
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.
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.