Problem locking a row for updating 
Author Message
 Problem locking a row for updating

How are you suppose to lock a row for updating
in a multi-user mode, using Dao calls to an Access
database. What is wrong with this code?

        rs.Open (dbOpenTable, "", dbDenyWrite);

        try
        {
                rs.SetCurrentIndex( _T("Registry Key") );

                COleVariant varKey (_T(Key), VT_BSTRT);
                BOOL found = rs.Seek( _T("="), &varKey );
                if ( found )
                {
                        rs.Edit();
                        rs.m_Registry_Value = Value;
                        rs.m_Updated        = COleDateTime::GetCurrentTime();
                        rs.Update();
                        rs.Close();
                }

What seems to happen is  that since the record is not locked until
the Edit(), if multiple user seek the same record, they will get the same
value and try to create duplicate records in another table.

----------------------------------------------------------------------------
--


274 Canterbury Road
Rochester NY  14607



Sun, 21 May 2000 03:00:00 GMT  
 Problem locking a row for updating

Quote:

>How are you suppose to lock a row for updating
>in a multi-user mode, using Dao calls to an Access
>database. What is wrong with this code?
>    rs.Open (dbOpenTable, "", dbDenyWrite);
>    try
>    {
>            rs.SetCurrentIndex( _T("Registry Key") );
>            COleVariant varKey (_T(Key), VT_BSTRT);
>            BOOL found = rs.Seek( _T("="), &varKey );
>            if ( found )
>            {
>                    rs.Edit();
>                    rs.m_Registry_Value = Value;
>                    rs.m_Updated        = COleDateTime::GetCurrentTime();
>                    rs.Update();
>                    rs.Close();
>            }
>What seems to happen is  that since the record is not locked until
>the Edit(), if multiple user seek the same record, they will get the same
>value and try to create duplicate records in another table.
>----------------------------------------------------------------------------
>--


>274 Canterbury Road
>Rochester NY  14607

Open the Table with a DenyRead + DenyWrite. Or, to guarantee no one
will create a duplicate, open the entire database in Exclusive mode.
Keep in mind, that you cannot lock a "Row" in Access. It locks a 2K
page and also an insidious Read lock if the fields are indexed.

Get PR-Tracker -- tracks problem reports, defects, bugs
INFORMATION:  http://www.prtracker.com/info.html
DOWNLOAD:     http://www.prtracker.com/download.html



Sun, 21 May 2000 03:00:00 GMT  
 Problem locking a row for updating

I'm not sure about the syntax for VB, but the Jet engine supports
pessimistic locking, which locks a 2K page contains the record when you
execute the Edit() method.

--
Randy Baker (remove Z from address in email replies)

Quote:

>How are you suppose to lock a row for updating
>in a multi-user mode, using Dao calls to an Access
>database. What is wrong with this code?

> rs.Open (dbOpenTable, "", dbDenyWrite);

> try
> {
> rs.SetCurrentIndex( _T("Registry Key") );

> COleVariant varKey (_T(Key), VT_BSTRT);
> BOOL found = rs.Seek( _T("="), &varKey );
> if ( found )
> {
> rs.Edit();
> rs.m_Registry_Value = Value;
> rs.m_Updated        = COleDateTime::GetCurrentTime();
> rs.Update();
> rs.Close();
> }

>What seems to happen is  that since the record is not locked until
>the Edit(), if multiple user seek the same record, they will get the same
>value and try to create duplicate records in another table.

>---------------------------------------------------------------------------
-
>--


>274 Canterbury Road
>Rochester NY  14607



Tue, 30 May 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Problem locking a row for updating

2. single row updates effect multiple rows....

3. Cannot update , table locked problem

4. Row Level Locking

5. Repost: database/table/row locking

6. row level locking under VC++/MFC/CRecordset and ODBC with SQL 7.0

7. row-level locking

8. row-level locking with DAO

9. Database row lock

10. row level locking under VC++/MFC/CRecordset and ODBC with SQL7.0

11. row-level locking with DAO

12. Database row lock

 

 
Powered by phpBB® Forum Software