Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Opening CDatabase in thread function

Posted on 1997-09-11
4
Medium Priority
?
251 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 600 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and 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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

927 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