ADOQuery in threads...

I tried to use a TADOQuery (delphi 5) object in a TThread. On the TADOQuery.Create, an exception was raised that 'CoInitialize' had not been called. So I simple called ole2.CoInitialize(nil), and without knowing what truly happens, everything seems to work. Even if I launch 50 threads and let them query an access database, all results seems to be allright.

- Is this ok, or just a dirty workaround?
- the delphi help states that bde access connection should not be used in threads, since the ADO library would not be thread safe. Is this still true, and so applicable to the new ADO components as well?
- Performance within the threads seems to be a little slow. Is this due to the simulanious reads of the access database, or are the ADO calls not handled in parallel?
leon321Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

john_mCommented:
You are correct in calling CoInitialize in the thread. Before any thread other than the main VCL thread makes any calls to the COM sub system, that thread must be initialised to use the system. Since ADO is inherently a member of the COM subsystem you must call CoInitialise. I haven't used the Delphi 5 ADO components, unfortunately they weren't around 12 months ago when I started working with ADO, however I'd assume that you would also have to call CoUninitialize before your thread terminates. In the words of Microsoft CoUninitialize....

"Closes the COM library on the current thread, unloads all DLLs loaded by the thread, frees any other resources that the thread maintains, and forces all RPC connections on the thread to close."

Hope that this helps your understanding,




John.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.