Solved

Opening CDatabase in thread function

Posted on 1997-09-11
4
237 Views
Last Modified: 2013-12-03
VC++ and MFC: I am trying to open a CDatabase object and use a CRecordset object with it. If I open the CDatabase object with OpenEx in the main process thread of my app, all is fine for both win95 and NT. However, if I open it in a thread function, I get an exception when I close the recordset ON WIN95 ONLY (NT works ok).
0
Comment
Question by:psen
[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
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
vinniew earned 200 total points
ID: 1406599
This may or may not be the reason, you'll have to search through the MFC source to be sure.

When you create a thread, you lose the message pump capability.  If you have any functions that require a callback window, you are out of luck.

My second idea is that you have different versions of the ODBC drivers and they behave differently.

My third idea is that you didn't link with the right library.  Be sure to use libs with 'mt' at the end.

My fourth idea is that you are compiling with the debug and the release version of MFC at the same time.  That's happened to me before, too.


In any case, you either need to post more info, or send me the project for me to know for sure if any of these are the reason.


V

0
 

Author Comment

by:psen
ID: 1406600
I thought it was to do with using CreateThread in an MFC app. However, I now use AfxBeginThread which is supposed to be safer in MFC. The exception (an access violation) is actually occuring in ORA72.DLL (I'm using the MS Oracle ODBC driver) when the thread tries to terminate. Stepping through the MFC source, the exception occurs when the thread is attempting to use the delete operator to remove the CDatabase object. I have checked all your points and think I'm ok, but can you explain the message pump one more - should I perhaps use a UI thread instead of a worker thread?
0
 

Author Comment

by:psen
ID: 1406601
One further thought - under win95, the ODBC oracle driver uses ORA72.DLL, whereas under NT, it uses ORA73.DLL - could it be that 72 is not multi-threaded whereas 73 is?
0
 
LVL 3

Expert Comment

by:vinniew
ID: 1406602
It could be.  I'm not familiar with those dll's.  You might want to try swapping and see what happens.

If the exception happens on the delete, it's probably not a thread problem.  How does it act if you allocate using the stack(make it global)?

Also, if you run your program in debug, you'll get a breakpoint at the exact location the exception occurs, what is the statement there?

Also, you may want to put something like:

if (myDatabase)
delete myDatabase;


Hasta,

V

0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

738 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