Solved

Opening CDatabase in thread function

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

776 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