Click to See Complete Forum and Search --> : Worker threads and CDaoDatabase


EricNielsen
May 5th, 1999, 11:10 AM
I have an application in which my class runs a database
analysis. One of the my class members is a CDaoDatabase
object. In my analysis method I retrieve the active
database name as follows:

CString dbPath = m_db.GetName();

My problem: When I run this analysis method from the
main thread everything works just fine. But, when I
run it in a worker thread (which is what I want to do!)
I get an exception:

DAO350.DLL: 0xC0000005: Access Violation

I have traced the code in the debugger, and all the
CDaoDatabase members are EXACTLY the same whether in the
main thread or a worker thread. Anyone have any ideas on
why the CDaoDatabase::GetName() method fails when called
in the worker thread?

Below is the code from ..\Vc\mfc\src\Daocore.cpp. I have
indicated the line of code which fails.

Any enlightenment would be greatly appreciated!!

Eric

=========================================================

CString CDaoDatabase::GetName()
{
ASSERT_VALID(this);
ASSERT(IsOpen());
ASSERT(m_pDAODatabase != NULL);

COleVariant var;
//<< Blows up on the following statement >>
DAO_CHECK(m_pDAODatabase->get_Name(&V_BSTR(&var)));
var.vt = VT_BSTR;
return V_BSTRT(&var);
}




Eric

Cosmin
May 5th, 1999, 04:09 PM
Hi!

As long as I remember, DAO components are not thread-safe. This means that if you have a pointer to such an interface and you use it in the same time (from some threads), you'll get the exception you mentioned.
Hope it works!

EricNielsen
May 5th, 1999, 04:33 PM
After posting my original message I found some info here about
DAO and threads. This is my first foray into both DAO and threads
so I've got a pretty steep learning curve, but I'm making progress.

I'm working right now on "compartmentalizing" the database object
with the worker thread. I'll be posting again when I hit my next
roadblock.

Eric