Solved

using CDataBase in a multithreaded app.

Posted on 2000-03-13
5
512 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
Comment Utility
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
Comment Utility
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
Comment Utility
My question was about MFC’s ODBC database classe(CDatabase,CRecordset,..)
and not DAO classes(CDaoDatabase , CDaoRecordest,...).
0
 
LVL 5

Expert Comment

by:vachooho
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now