Solved

Accessing a DB from thread

Posted on 2006-10-23
2
183 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 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

10 Experts available now in Live!

Get 1:1 Help Now