Re: Can't open MS Access database inside a thread

From: Mercury (me_at_spam.com)
Date: 02/18/05


Date: Fri, 18 Feb 2005 23:59:50 +1300

The CDao stuff uses the MS Access file sharing DAO DLL's under the hood and
that is the problem. DAO is fast but not thread safe.

The ODBC classes (CDatabase and CRecordset) are thread safe and for the
novice not quite as friendly or as fast as DAO. But they are safe!

The advice has been for years to cease using DAO for new apps and use ODBC -
it is now to use ADO. ODBC is not going to die off anytime soon, but it is
best to move forward. I still use ODBC in VC6, but use ADO in ASP.Net.

You now have a slight contradiction: in the orignal post you said CDao.....
and now say CDatabase and CRecordset....which is it? The former - a problem,
both - a problem, the latter - you have bugs. (Sorry - your not the OP -its
late :).

I suggest a) find out which technology and b) detail the error and post it
with source code & someone will help.

> More specificially, each thread has its own CDatabase and CRecordset;
> different threads access the same database mdb but different tables.

why?

DBMS are designed to manage concurrency for you. Don't try to pre-empt a
problem that someone else has spent years solving already - without a really
good reason.

- Tim

"r norman" <rsn_@_comcast.net> wrote in message
news:6oi611548lu5ntp77kdk1f98e0cop6ksoh@4ax.com...
> This is starting to scare me! What about CDatabase and CRecordset?
> Are they thread safe?
>
> More specificially, each thread has its own CDatabase and CRecordset;
> different threads access the same database mdb but different tables.
>
> On Wed, 16 Feb 2005 19:38:37 +1300, "Mercury" <me@spam.com> wrote:
>
>>And... if you are going to use it in a thread, make sure you do not also
>>use
>>dao in the main thread ever while the secondary is active. It is not
>>thread
>>safe.
>>
>>You can use it in multiple threads so long as only one thread is active at
>>a
>>time IE AfxDaoTerm is called before AfxDaoInit in a new thread.
>>
>>
>>"Crystal" <linwingyee@hotmail.com> wrote in message
>>news:%23avWMA%23EFHA.228@TK2MSFTNGP15.phx.gbl...
>>> Dear All,
>>>
>>> I want to know why I can't use CDaoDatabase [db] to open the access
>>> database
>>> inside a thread. "Access violation" happens.
>>>
>>> Thanks!
>>> Crystal
>>>
>>>
>>>
>>>
>>
>



Relevant Pages


Loading