Monday, August 16, 2010

ADO Locking

A dynamic web site where database is used might need to support hundreds of users accessing th same database table at the same time. When more then one user is updating and reading data in a database table at the same time conflict may occurs. To prevent conflicts recorset Lock Type is used.

There are four types of locking provided by ADO
  • Optimistic
  • Pessimistic
  • Read-only
  • Batch optimistic
Note: Set this property before opening the Recordset.
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("northwind.mdb"))
set rs=Server.CreateObject("ADODB.recordset")
sql="SELECT * FROM Customers"
rs.CursorLocation=adUseClient
rs.CursorType=adOpenStatic
rs.LockType=adLockBatchOptimistic
rs.Open sql,conn rs.Close
conn.Close
%>

Constant Values
Constant Value Description
adLock -1 Unspecified type of lock. Clones inherits lock type from the original Recordset.
adLockReadOnly 1 Read-only records
adLockPessimistic 2 Pessimistic locking, record by record. The provider lock records immediately after editing
adLockOptimistic 3 Optimistic locking, record by record. The provider lock records only when calling update
adLockBatchOptimistic 4 Optimistic batch updates. Required for batch update mode

No comments:

Post a Comment