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
Solved

Accessing a DB from thread

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

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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…
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.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

790 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