Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sharing database connection with threads, instead of creating new ones

Status
Not open for further replies.

djjd47130

Programmer
Nov 1, 2010
480
0
0
US
I wanted to check into this before I attempt it. I am working on a couple threads which require fetching data from the database within the threads. Currently, based on all I've seen, I am creating a new database connection (TADOConnection) from within the threads. All works fine, except it would be great if I could obtain the connection object from somewhere outside the thread. Basically, I don't want to keep creating a new TADOConnection for each thread execution.

Is it possible to publish a TADOConnection property on the outside of the thread (thus assigning it when I create the thread) and then use that connection within the thread? All I would need to do then is create the TADODataSet inside the thread and assign its connection to this TADOConnection. I'm a little iffy about this, especially because I'm required to call CoInitialize and CoUninitialize when working with ADO in a thread.

JD Solutions
 
I already got my answer, it's a big fat NO. Since the TADOConnection is a COM structure, it can't be shared across threads.

JD Solutions
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top