Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

using CDataBase in a multithreaded app.

Posted on 2000-03-13
5
532 Views
Last Modified: 2013-11-20
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
Comment
Question by:mh_attar
5 Comments
 
LVL 3

Expert Comment

by:ghimireniraj
ID: 2612353
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
 

Expert Comment

by:romeroroly
ID: 2612363
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
 

Author Comment

by:mh_attar
ID: 2613048
My question was about MFC’s ODBC database classe(CDatabase,CRecordset,..)
and not DAO classes(CDaoDatabase , CDaoRecordest,...).
0
 
LVL 5

Expert Comment

by:vachooho
ID: 2613211
MFC's ODBC classes are thread-safe
You can use CDatabase and Crecordset classes in any app threads without worrying about simultaneous access.

0
 
LVL 11

Accepted Solution

by:
mikeblas earned 70 total points
ID: 2614100
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question