Microsoft KB Archive/190625

= FIX: ADO Client Cursors Report LockType = adLockPessimistic =

Article ID: 190625

Article Last Modified on 3/2/2005

-

APPLIES TO


 * Microsoft ActiveX Data Objects 1.5
 * Microsoft ActiveX Data Objects 2.0
 * Microsoft ActiveX Data Objects 2.1
 * Microsoft ActiveX Data Objects 2.5
 * Microsoft ActiveX Data Objects 2.6
 * Microsoft ActiveX Data Objects 2.7
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q190625



SYMPTOMS
ActiveX Data Objects (ADO) incorrectly reports that a client-side recordset opened with a LockType of adLockPessimistic was opened with pessimistic locking.

The ADO client cursor engine does not support pessimistic locking. If you ask ADO for a pessimistically locked client-side recordset, you actually receive an optimistically locked recordset instead, even though ADO did not change the value of the LockType property to adLockOptimistic.

With MDAC 2.1 sp2 the locktype is now returned as adlockbatchoptimistic(4).



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.

This bug has been fixed in MDAC 2.1 Service Pack 2 and later releases.



Steps to Reproduce Behavior
 Open a Standard.exe project in Visual Basic, and add a reference to the Microsoft ActiveX Data Object Library.  Copy and paste the following code into the form code window: Option Explicit Dim myconn As New ADODB.Connection Dim myrs As New ADODB.Recordset

Private Sub Form_Load Dim strConn As String

'Modify the connection string to point to your SQLOLEDB. strConn = "Provider=SQLOLEDB;Data Source=server;Initial Catalog=Northwind;" & _ "user id=user;Password=password"

myconn.CursorLocation = adUseClient myconn.Open strConn

'Request a pessimistically locked cursor. 'ADO's client cursor engine only supports optimistic locking. myrs.Open "SELECT * FROM Customers", myconn, _ adOpenStatic, adLockPessimistic, adCmdText MsgBox "MyRS.LockType = " & myrs.LockType & vbCrLf & _ "adLockPessimistic = " & adLockPessimistic & vbCrLf & _ "adLockOptimistic = " & adLockOptimistic myrs.Close End Sub  Run the form and note the output of the message boxes.

