Solved

Accessing a DB from thread

Posted on 2006-10-23
2
190 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

705 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