Thread Safe???? CRecordSet, ODBC.... 
Author Message
 Thread Safe???? CRecordSet, ODBC....

Hello,

I am just starting to learn DB access with VS6. I am
working through the example "Enroll", a student
database.

I want to know what is thread safe in CRecordSet,
CDatabase, and "ODBC".

If I have created two CRecordSets that open the same
data source, and I use them in different threads, is
there a potential problem with one thread writing a
record and another thread writing to that same record
at the same time and getting interleaved results? Or is
it thread safe?

If I have only ONE CRecordSet shared between
threads, are the internals of the recordset thread safe?

This is my first code for DB access on Windows. I am
a pretty welled seasoned C++ developer, but just new
at this.

Thank you.
Gilligan



Fri, 01 Jul 2005 22:42:49 GMT
 Thread Safe???? CRecordSet, ODBC....

It sounds like you are worried about the kinds of things that can happen
when more than one thread opens a stream for writing; it isn't really the
same thing with database systems.  Unless you are using an ODBC text file
driver, it just isn't going to happen that way.  DBMS's control the locks on
the data and there are things to watch out for in that area, such as dirty
reads, but mostly, with exceptions, ODBC drivers do some form of
interprocess communication with the db server (network, shared memory,
pipes) and the server keeps things in order.

It is possible that some ODBC drivers are not completely thread safe, but
it's been a while since I've seen one.  But in that case, you'd more likely
end up with some form of access violation than data corruption, but anything
is possible.

Don't know the internals of the CRecordSet, etc. stuff; so, can't say, but
I'd be surprised to find threading issues with those.

-Chris


Quote:

> Hello,

> I am just starting to learn DB access with VS6. I am
> working through the example "Enroll", a student
> database.

> I want to know what is thread safe in CRecordSet,
> CDatabase, and "ODBC".

> If I have created two CRecordSets that open the same
> data source, and I use them in different threads, is
> there a potential problem with one thread writing a
> record and another thread writing to that same record
> at the same time and getting interleaved results? Or is
> it thread safe?

> If I have only ONE CRecordSet shared between
> threads, are the internals of the recordset thread safe?

> This is my first code for DB access on Windows. I am
> a pretty welled seasoned C++ developer, but just new
> at this.

> Thank you.
> Gilligan



Sat, 02 Jul 2005 07:11:52 GMT
 Thread Safe???? CRecordSet, ODBC....

Hi Gilligan

Yes, the MFC ODBC classes are threadsafe *unless* you use a driver which is
not thread safe, like the Access ODBC driver. Which if I recall correctly,
is the one that that sample was based on. But if anything in the chain is
not thread safe, then nothing is.  So if you use Jet, then even though the
MFC classes are thread safe, even though ODBC is threadsafe, your app is
not thread safe because the ODBC driver is not.

I think that you're OK with sharing a database between 2 recordsets, but I
recommend giving each Recordset it's own DB. Otherwise the DB can be a
bottleneck and can limit performance.

I hope this helps,

Russ Gray
Microsoft Developer Support

This posting is provided AS IS with no warranties, and confers no rights.

Are you secure? For information about the Microsoft Strategic Technology
Protection Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/security.



Sat, 02 Jul 2005 07:52:33 GMT
 
 [ 3 post ] 

 Relevant Pages 

1. CDatabase and CRecordset Thread safe in VC 5.0?

2. HELP -- odbc thread safe?

3. Is ODBC thread-safe?

4. MS Access ODBC driver, Is it thread safe?

5. JET ODBC Driver thread-safe????

6. ODBC is Thread safe outside SQLServer?

7. Is Microsoft Access ODBC driver thread-safe?

8. Multi-thread safe Paradox ODBC driver???

9. Is ODBC thread safe?

10. Is VFP ODBC driver thread-safe?

11. Is VFP ODBC driver thread-safe?

12. Multi-thread safe Paradox ODBC driver???


 
Powered by phpBB® Forum Software