Solved

Opening CDatabase in thread function

Posted on 1997-09-11
4
233 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
  • 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
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…

830 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