• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 636
  • Last Modified:

using CDataBase in a multithreaded app.

I want to use ODBC in a multithreaded application.Should I worry about simultanios access to record or ODBC itself manages it (by some sort of locking)? In other words should I use critical sections , etc when updating the database or executing a query ?
0
mh_attar
Asked:
mh_attar
1 Solution
 
ghimirenirajCommented:
you must if you want proper data manipulation or retrieval unless you are sure about the exact sequence of the threads accessing the database

ghimireniraj
0
 
romerorolyCommented:
If you are using DAO, it's not good idea. DAO don't support multiread/multiwrite actions.
If you use DAO, you have to create a critical section to regulate the thread access to database.
You can use ADO. It support multiread/multiwrite actions.


I hop that you resolve your problem.

Have a lot of fun!
0
 
mh_attarAuthor Commented:
My question was about MFC’s ODBC database classe(CDatabase,CRecordset,..)
and not DAO classes(CDaoDatabase , CDaoRecordest,...).
0
 
vachoohoCommented:
MFC's ODBC classes are thread-safe
You can use CDatabase and Crecordset classes in any app threads without worrying about simultaneous access.

0
 
mikeblasCommented:
I see that you still haven't received a clear, accurate answer.  Let me try to remedy that for you:

MFC's CDatabase and CRecordset classes are thread-safe at the class level. That is, if you create a CDatabase in a particular thread, you can call it all you want. If you want to work with a CDatabase object in a different thread, you need to create a new CDatabase object.

You can hand a CDatabase or a CRecordset from one thread to another as long as you're sure only one thread is accessing it at a time. If you need to do that, you need to investigate using synchronization objects.

That is, you can _not_ share a CDatabase or a CRecordset object from one thread to another without protection.

Also, this all assumes the underlying ODBC drivers you're using are thread-safe. If they're not, then you're stuffed. In this modern day, there should be no thread-unsafe drivers. But I guess it's possible that you'll run into an old, or buggy, driver.

..B ekiM
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now