Solved

Accessing a DB from thread

Posted on 2006-10-23
2
184 Views
Last Modified: 2013-11-20
Hi, I used to have the db connection in my dialog:
MyDlg::AccessDB()
{
..
}

But I have  a lot of data to transfer, so I have put it in a thread, like this, creating the thread from the dialog:
AfxBeginThread(WorkerThreadProc,this,THREAD_PRIORITY_NORMAL,0,0,NULL);

Then the implementation of the function looks like this:

UINT WorkerThreadProc( LPVOID Param )
{
_ConnectionPtr m_DBConn;
m_DBConn.CreateInstance( __uuidof( Connection ) );
}

** I could create the instance to the _ConnectionPtr, when I did it in the dialog class, but not hire in the worker thread function. Anyone have any good idea why ?
0
Comment
Question by:win32
2 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 100 total points
ID: 17787304
You need to call CoInitialize or CoInitializeEx in the beginning of worker thread, and CoUninitialize/CoUninitializeEx in the end.
0
 

Author Comment

by:win32
ID: 17938303
Dough.. right
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
maven archtype selection in eclipse 1 53
wait notify demo infinite loop 3 95
sumHeights2  challenge 7 87
Dell Alienware Graphics Amplifier Driver for non-Alienware systems 18 190
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now