Solved

Opening CDatabase in thread function

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now