CDaoRecordset::Close() does not release table lock 
Author Message
 CDaoRecordset::Close() does not release table lock


I'm having problems in locking a table using DAO.
I need to lock the "Chart of Accounts" table when posting
new a new record, because I have to make
sure that the "AccountNo" (PrimaryKey) is unique and there
should be only one record that has "Y"
in the "Chart of Account.CurrRE" field.

I've managed to get table lock by opening it with
dbDenyWrite, while the table is also open by other
recordset with dbReadOnly for browsing and displaying

The problem is it always fails when opening with
dbDenyWrite the second time, although the first was closed.

I wrote a sample code below to describe the error. Any
idea to overcome this would be very much appreciated.

Thanks in advance.


BOOL CTESTDoc::OnNewDocument()
        if (!CDocument::OnNewDocument())
                return FALSE;

        // TODO: add reinitialization code here
        // (SDI documents will reuse this document)
        CDaoDatabase cdb;
        CDaoTableDef TableDef(&cdb),td(&cdb);
        CDaoRecordset Recordset(&cdb),rs(&cdb);
        cdb.Open("C:\\2 Project\\TEST\\GA.MDB");
                td.Open("Chart of Accounts");
                rs.Open(&td,dbOpenTable,dbReadOnly); //
assume this is for displaying purposes
                TableDef.Open("Chart of Accounts");
(&TableDef,dbOpenTable,dbDenyWrite); // assume this is
only for posting purposes
                Recordset.Close(); // This should free the
table lock, somehow it doesn't
        catch (CDaoException *e)
                TableDef.Open("Chart of Accounts");
                // at this point (2nd time opening
with 'denywrite'
                // an error thrown, the table claimed to
be opened exclusively by other user

        catch (CDaoException *e)
        return TRUE;


Mon, 01 Nov 2004 00:42:34 GMT  
 [ 1 post ] 

 Relevant Pages 

1. DAO Execute() method locks a table and does not release it

2. DAO3.60 - getting error 3260 when doing CDaoRecordset::Update

3. CDaoRecordSet -- CDaoRecordSet -- CDaoRecordSet

4. CDaoRecordsets lock database

5. Problem with CDaoRecordset.FindFirst locking up system

6. Does CDAORecordset lock records on Edit/AddNew ?

7. Locked CDaoRecordset

8. Computer locks up when doing RasDial()

9. Close not to close

10. External Tables with CDaoRecordset

11. CDaoRecordSet as table-type.

12. CDaoRecordset Table-type


Powered by phpBB® Forum Software