Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

using CDataBase in a multithreaded app.

Posted on 2000-03-13
5
Medium Priority
?
575 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
[X]
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
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 280 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

721 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