Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Querying on existing recordsets

Querying on existing recordsets

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasehelpquestioncom
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SelvaKr
    wrote on last edited by
    #1

    Hi My application is in C++/ATL/COM and uses the Access database for storing configurations. Various DLLs and EXEs (and threads) that are part of my application query the database when needed. When doing so, I am getting the database locked message ('[Microsoft][ODBC Microsoft Access Driver] The database has been placed in a state by an unknown user that prevents it from being opened or locked' in the log) randomly and the application fails to continue. I am assuming that this problem happens due to the shared access of the database. My question is: Can i get the complete database in memory (in form of recordsets for every table) during the launch and query the recordsets directly instead of querying the database? I believe this might solve the database locking problem. Any help is appreciated. Thanks Selva

    Selva

    J 1 Reply Last reply
    0
    • S SelvaKr

      Hi My application is in C++/ATL/COM and uses the Access database for storing configurations. Various DLLs and EXEs (and threads) that are part of my application query the database when needed. When doing so, I am getting the database locked message ('[Microsoft][ODBC Microsoft Access Driver] The database has been placed in a state by an unknown user that prevents it from being opened or locked' in the log) randomly and the application fails to continue. I am assuming that this problem happens due to the shared access of the database. My question is: Can i get the complete database in memory (in form of recordsets for every table) during the launch and query the recordsets directly instead of querying the database? I believe this might solve the database locking problem. Any help is appreciated. Thanks Selva

      Selva

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      A better solution would be to locate and fix the problems. Some hints:

      • Open database read only when no data should be written
      • When opening/accessing and the database is locked, retry operation after some time
      • When writing to the database, lock the thread so that other threads are blocked
      • When writing, close the database aftwerwards to avoid locking states
      S 1 Reply Last reply
      0
      • J Jochen Arndt

        A better solution would be to locate and fix the problems. Some hints:

        • Open database read only when no data should be written
        • When opening/accessing and the database is locked, retry operation after some time
        • When writing to the database, lock the thread so that other threads are blocked
        • When writing, close the database aftwerwards to avoid locking states
        S Offline
        S Offline
        SelvaKr
        wrote on last edited by
        #3

        Hi Jochen Thanks for your response. I am already reviewing the code and doing that. But still it fails at times. So I was thinking whether i could keep them all in memory so that the DB hits can be avoided. Please share your thoughts. Thanks Selva

        Selva

        J 1 Reply Last reply
        0
        • S SelvaKr

          Hi Jochen Thanks for your response. I am already reviewing the code and doing that. But still it fails at times. So I was thinking whether i could keep them all in memory so that the DB hits can be avoided. Please share your thoughts. Thanks Selva

          Selva

          J Offline
          J Offline
          Jochen Arndt
          wrote on last edited by
          #4

          If you have it in memory, you won't get changings. And if you add code to support changings during runtime, you may not need a database. Assuming that all modules must then use only one function to access the memory db, why not implement the only function using direct db access? In both cases, that function must be thread safe using locking. I think that's your problem: You access the db from different threads which may fail when the db is locked by another thread. You will have similar problems when using a memory image that is modified when not using locking (but without getting an error message).

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups