Solved

Accessing a DB from thread

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

Suggested Solutions

Title # Comments Views Activity
xyBalance chalenge 58 102
sameEnds challenge 3 187
dog bark java program 15 119
Authenticate using sesu from script 7 107
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: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

740 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