Under what circumstances should adLockOptimistic be used and under what circumstances should adLockPessimistic be used ....

Source: Internet
Author: User
Under what circumstances should adLockOptimistic be used and under what circumstances should adLockPessimistic be used...
Under what circumstances should adLockOptimistic be used, adLockPessimistic should be used, adOpenKeyset should be used, adOpenDynamic--should be used --

 

With a small piece of information:
-----------------------------------
Constant Value description
-----------------------------------
The default value of adOpenForwardOnly 0 is to start a Forward-Only cursor (Forward Only ).
AdOpenKeyset 1 starts a Keyset type cursor.
AdOpenDynamic 2 starts a Dynamic type cursor.
AdOpenStatic 3 starts a Static cursor.
-----------------------------------
The preceding cursor types directly affect all attributes and methods of the Recordset object. The following lists the differences between them.

---------------------------------------------
Recordset attribute adOpenForwardOnly adOpenKeyset adOpenDynamic adOpenStatic
---------------------------------------------
AbsolutePage does not support read/write.
AbsolutePosition does not support read/write.
ActiveConnection can be read/written or read/write
BOF read-only
Bookmark does not support read/write.
CacheSize: readable/writable
CursorLocation: readable/writable
CursorType can be read/written or read/write
EditMode read-only
EOF read-only
The Filter can read and write, and can read and write.
LockType: readable/writable
MarshalOptions: readable/writable
MaxRecords
PageCount does not support read-only and read-only
PageSize: readable/writable
RecordCount does not support read-only and read-only
Source: readable/writable
State read-only
Status read-only
AddNew support
Support for CancelBatch
Supported CancelUpdate
Clone is not supported.
Support for Close
Support for Delete
GetRows support
Move is not supported.
Supported by MoveFirst
Supported by MoveLast
Supported by MoveNext
Supported by MovePrevious
Supported by NextRecordset
Open Support
Requery support
Not supported by Resync
Supports support
Update support
Supported by UpdateBatch
----------------------------------------
The NextRecordset method is not applicable to Microsoft Access databases.

LockType
The LockType parameter of the Open method of the Recordset object indicates the Lock type to be used. If this parameter is ignored, the system uses the LockType attribute of the Recordset object as the default value. The LockType parameters include adLockReadOnly, adLockPrssimistic, adLockOptimistic, and adLockBatchOptimistic, which are described as follows:

-----------------------------------
Constant Value description
-----------------------------------
AdLockReadOnly 1 is the default value. The Recordset object is started in read-only mode and cannot run AddNew, Update, Delete, and other methods.
AdLockPrssimistic 2 when the data source is being updated, the system will temporarily lock the actions of other users to maintain data consistency.
AdLockOptimistic 3 when the data source is being updated, the system does not lock the actions of other users. Other users can add, delete, and modify data.
AdLockBatchOptimistic 4 when the data source is being updated, other users must change the CursorLocation attribute to adUdeClientBatch to add, delete, and modify the data.

===== Define some constants for database connection
<%
Const adOpenForwardOnly = 0' the cursor only browses records forward. pagination, Recordset, and BookMark are not supported.
Const adOpenKeyset = 1' indicates the keyset cursor. modifications made by other users to the record are reflected in the record set. However, adding or deleting records by other users is not reflected in the record set. Supports paging, Recordset, and BookMark
Const adOpenDynamic = 2' the most dynamic cursor function, but the most resource consumption. The added or deleted records modified by the user on the record description will be reflected in the record set. Supports full-featured browsing (ACCESS is not supported ).
Const adOpenStatic = 3' the static cursor is only a snapshot of the data. The changes you make to the record description, adding or deleting records, will not be reflected in the record set. Supports moving forward or backward

Const adLockReadOnly = 1' lock type, default, read-only, cannot be modified
Const adLockPessimistic = 2' lock the record immediately when editing, the safest way
Const adLockOptimistic = 3' the record set is locked only when the Update method is called, and other operations before this can still change, insert, and delete the current record.
Const adLockBatchOptimistic = 4' records are not locked when being edited, but changes, inserts, and deletes are completed in the batch processing mode.

Const ad1_text = & H0001
Const adCmdTable = & H0002
%>

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

When ADO Recordset's CursorLocation = AdUseClient, only AdOpenStatic/AdOpenForwardOnly
The other two have the same effect as AdOpenStatic, that is, the CursorType is set to adOpenStatic.

If it is AdUseServer, the above four cursortypes can be used in SQL Server, but the Resync method in RecordSet is only
Only the CursorType of the adOpenKeyset can be used, and the AdOpenStatic cannot be used.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.