Solved

using CDataBase in a multithreaded app.

Posted on 2000-03-13
5
538 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to you can convert your project to a Maven project and the Maven plugin should download the source 1 51
sum67 challenge 35 116
either24  challenge 19 105
Sed question 2 123
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

756 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