A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.
We have a HTTP server made with Delphi that uses the Borland database engine (BDE). We want to replace the BDE with ADO. Is ADO threadsafe? I can't find anything to tell me that it is or isn't. With the BDE I had to use particular components and set specific properties to make it threadsafe. Do I have to do something similar with ADO?
> ADO is based on COM. As long as you follow the COM rules about threading (apartments and passing interface pointers between them) you don't need to worry about thread safety.
> You may need to worry about performance, but that's a different question. ;-)
ADO supports free threading, so if your provider implemented a free-threaded object, then apartments shouldn't come into play, but you do have to know what you are doing.
Tuesday, May 16, 2006
You should be fine.
In the simple case, just don't share ADO connections between threads. You can do it in some instances, but that also depends on the OLEDB driver for the database in question.
Normally, you just call CoInitialize[Ex]() in the thread execute function, create your ADO connection, do what you need to to, close the connection, and then call CoUninitialize().
Make sure all ADO objects are destroyed before calling CoUninitialize(). ;-)
If you're using an OLEDB provider to connect to your data source via ADO, you can follow two simple rules to take advantage of connection pooling:
1.) Use the exact same connection string on every connection object created in every thread.
2.) Keep at least one of those connection objects initialized (the connection should't be open, but the object has to be there) per process.
3.) Open each connection as late as possible and close it as early as possible.
Also, if you're just creating threads to query the database, you can let the connection take care of that by using asynchronous executions and client sided cursors (client sided is the most flexible).
If you need to pass recordsets between threads, you can disconnect them and serialize them first, then restore them in another thread after passing the serialized data over.
This topic is archived. No further replies will be accepted.Other recent topics
Powered by FogBugz