Lock Types: Managing Access to a Recordset
There are four record-locking schemes in ADO. Each has its own advantages and disadvantages, as described in the following sections. The record lock type is indicated by either the LockType property of the Recordset object or the LockType parameter of the Open method of the Recordset object. The LockType parameter of the Open method is the fourth parameter in the parameter list.
Either one of these (the parameter or the property) can be set to one of the four valid constants from the LockTypeEnum enumeration shown in Table 5-15.
Value |
Description |
adReadOnly |
Indicates that the recordset will use a read-only record-locking scheme. |
adLockOptimistic |
Indicates that the recordset will use an optimistic record-locking scheme. |
adLockPessimistic |
Indicates that the recordset will use a pessimistic record-locking scheme. |
adLockBatchOptimistic |
Indicates that the recordset will use a batch optimistic record-locking scheme. |
Read-Only Locks
A read-only record-locking scheme is the simplest locking scheme of the four available. Basically, a read-only recordset does not allow adding or editing of records; therefore, the records themselves do not need to be locked for editing at all.
The following example illustrates how to open a recordset with the read-only record-locking scheme:
rst.Open "Authors", _ "DSN=BiblioDSN", _ adOpenKeyset, _ adLockReadOnly ' cannot alter data rst.Close
You should use read-only ...
Get ADO: ActiveX Data Objects now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.