I found BUG??? DAO exception 
Author Message
 I found BUG??? DAO exception

Hi,

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
purposes.

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.

Regards,
Ivan

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");
        try
        {
                td.Open("Chart of Accounts");
                rs.Open(&td,dbOpenTable,dbReadOnly); //
assume this is for displaying purposes
                TableDef.Open("Chart of Accounts");
                Recordset.Open
(&TableDef,dbOpenTable,dbDenyWrite); // assume this is
only for posting purposes
                Recordset.Close(); // This should free the
table lock, somehow it doesn't
                TableDef.Close();
        }
        catch (CDaoException *e)
        {
                e->Delete();
        }
        try
        {
                TableDef.Open("Chart of Accounts");
                Recordset.Open
(&TableDef,dbOpenTable,dbDenyWrite);
                // at this point (2nd time opening
with 'denywrite'
                // an error thrown, the table claimed to
be opened exclusively by other user

                Recordset.Close();
                TableDef.Close();
        }
        catch (CDaoException *e)
        {
                e->Delete();
        }
        return TRUE;

Quote:
}



Mon, 01 Nov 2004 22:00:44 GMT  
 I found BUG??? DAO exception
You have opened the table two times:

rs.Open()  and Recordset.Open()

'rs' is never closed.  Are you only allowed one lock per table (and it is
still open).
Will you also add a rs.Close() in addition to the Recordset.Close()

--
Hank Williams
Quantum Technologies, Inc.


| Hi,
|
| 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
| purposes.
|
| 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.
|
| Regards,
| Ivan
|
|
| 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");
| try {
     td.Open("Chart of Accounts");
     rs.Open(&td,dbOpenTable,dbReadOnly); // assume this is for displaying
purposes
     TableDef.Open("Chart of Accounts");
     Recordset.Open(&TableDef,dbOpenTable,dbDenyWrite); // assume this is
only for posting urposes
     Recordset.Close(); // This should free the table lock, somehow it
doesn't
    TableDef.Close();
    }
| catch (CDaoException *e)
    {
    e->Delete();
    }
| try {
    TableDef.Open("Chart of Accounts");
    Recordset.Open(&TableDef,dbOpenTable,dbDenyWrite); // at this point (2nd
time opening with 'denywrite'
| // an error thrown, the table claimed to
| be opened exclusively by other user
|
| Recordset.Close();
| TableDef.Close();
| }
| catch (CDaoException *e)
| {
| e->Delete();
| }
| return TRUE;
| }
|



Tue, 02 Nov 2004 03:33:37 GMT  
 I found BUG??? DAO exception
rs.Open() is in shared mode, i.e., dbReadOnly
rs.Open() still open while the first Recordset.Open()
successfully open the table. Recordset.Open() with
dbDenyWrite is the one that lock the table. After
Recordset.Close(), the lock should be freed. Somehow, it
still hold the lock, and the second Recordset.Open()
throws an error claiming that other user has the lock.

Quote:
>-----Original Message-----
>You have opened the table two times:

>rs.Open()  and Recordset.Open()

>'rs' is never closed.  Are you only allowed one lock per
table (and it is
>still open).
>Will you also add a rs.Close() in addition to the
Recordset.Close()

>--
>Hank Williams
>Quantum Technologies, Inc.



>| Hi,
>|
>| 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
>| purposes.
>|
>| 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.
>|
>| Regards,
>| Ivan
>|
>|
>| 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");
>| try {
>     td.Open("Chart of Accounts");
>     rs.Open(&td,dbOpenTable,dbReadOnly); // assume this
is for displaying
>purposes
>     TableDef.Open("Chart of Accounts");
>     Recordset.Open

(&TableDef,dbOpenTable,dbDenyWrite); // assume this is

- Show quoted text -

Quote:
>only for posting urposes
>     Recordset.Close(); // This should free the table
lock, somehow it
>doesn't
>    TableDef.Close();
>    }
>| catch (CDaoException *e)
>    {
>    e->Delete();
>    }
>| try {
>    TableDef.Open("Chart of Accounts");
>    Recordset.Open(&TableDef,dbOpenTable,dbDenyWrite); //
at this point (2nd
>time opening with 'denywrite'
>| // an error thrown, the table claimed to
>| be opened exclusively by other user
>|
>| Recordset.Close();
>| TableDef.Close();
>| }
>| catch (CDaoException *e)
>| {
>| e->Delete();
>| }
>| return TRUE;
>| }
>|

>.



Wed, 03 Nov 2004 00:10:23 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. VC exception bug or bug in my code?

2. A Hard To Find Bug - Found

3. DAO exception 3075

4. DAO Exception on Memo Field

5. DAO unhandled Exception in Close() command

6. DAO SDK & CString Exceptions

7. DAO Close exception on RemoveKey call

8. DAO memo field exception (limitation) in VC 6.0

9. dao database open exception

10. Unhandled Exception in DAO Update()

11. DAO Table Open() exceptions

12. Question: Exception Handling in DAO + 1

 

 
Powered by phpBB® Forum Software