Querying on existing recordsets
-
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
-
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
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
-
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
-
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
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).