This topic applies to the MFC ODBC classes.
This topic explains:
When you use a recordset to update a record on the data source, your application can lock the record so no other user can update the record at the same time. The state of a record updated by two users at the same time is undefined unless the system can guarantee that two users cannot update a record simultaneously.
This topic applies to objects derived from CRecordset in which bulk row fetching has not been implemented. If you have implemented bulk row fetching, some of the information does not apply. For example, you cannot call the Edit and Update member functions. For more information about bulk row fetching, see Recordset: Fetching Records in Bulk (ODBC).
The database classes provide two :
Optimistic locking (the default)
Updating a record occurs in three steps:
You begin the operation by calling the member function.
You change the appropriate fields of the current record.
You end the operation вЂ” and normally commit the update вЂ” by calling the member function.
Optimistic locking locks the record on the data source only during the Update call. If you use optimistic locking in a multiuser environment, the application should handle an Update failure condition. Pessimistic locking locks the record as soon as you call Edit and does not release it until you call Update (failures are indicated through the CDBException mechanism, not by a value of FALSE returned by Update). Pessimistic locking has a potential performance penalty for other users, because concurrent access to the same record might have to wait until completion of your application's Update process.
Locking Records in Your Recordset
If you want to change a recordset object's locking mode from the default, you must change the mode before you call Edit.
To change the current locking mode for your recordset
Call the member function, specifying either CRecordset::pessimistic or CRecordset::optimistic.
The new locking mode remains in effect until you change it again or the recordset is closed.
Relatively few ODBC drivers currently support pessimistic locking.