Click to See Complete Forum and Search --> : CDaoDatabase troubles in Visual C++ v6.0 Service Pack 2


May 5th, 1999, 10:03 AM
Has anyone else had trouble with their CDaoDatabase programs when compiling under Visual C++ 6.0 Service Pack 2?

The following code worked under v5.0 but now throws an exception.


CDaoDatabase myDatabase;

myDatabase.Open( "C:\MyDB.mdb" );




I have also tryed downloading some of the CDaoDatabase examples provided on this site, and those do not seem to work either. The problem appears to exist in the AfxDaoInit() function. I used the Visual Debugger to trace the problem to this function, and I noticed from some of the CDaoDatabase apps on this site, that they also suffer from the problem.

If anyone has any idea what the problem is or can offer a solution, I would appreciate it. Thanks in advance.

ksheeraj
May 7th, 1999, 04:06 AM
If you step in to the source code of the CDaoDatabase->Open"() Method you will find that the wrapper class for the DAOEngine is trying to Initlize the DBEngine.They have function called AfxDaoInit() inside the Open call of CDaoDatabase.And very first line of the function AfxDaoInit() is calling ::CoInitlze(NULL).But you know what your App already called ::CoInitlize(NULL).DAOEngine is register as Apartment Model in to registery.It means you can not create Instance of DBEngine from MTA.It will always give you error code "0x80010106".And description is says "Thread Mode cannot be set by Another process".
To get rid of this problem You have to use DBEngine as a COM object .Don not use wrapper calss i.e CDaoDatabase classes.
Ksheeraj

39639,Leslie St.
Apt #157
Fremont USA 94538