FIX: ADO Client Cursors Report LockType = adLockPessimistic (190625)



The information in this article applies to:

  • ActiveX Data Objects (ADO) 1.5
  • ActiveX Data Objects (ADO) 2.0
  • ActiveX Data Objects (ADO) 2.1
  • ActiveX Data Objects (ADO) 2.5
  • ActiveX Data Objects (ADO) 2.6
  • ActiveX Data Objects (ADO) 2.7
  • Microsoft Visual Basic Professional Edition for Windows 5.0
  • Microsoft Visual Basic Professional Edition for Windows 6.0
  • Microsoft Visual Basic Enterprise Edition for Windows 5.0
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0

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.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Open a Standard.exe project in Visual Basic, and add a reference to the Microsoft ActiveX Data Object Library.
  2. 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
    					
  3. Run the form and note the output of the message boxes.

REFERENCES

ADO 2.0 documentation

Modification Type:MinorLast Reviewed:3/2/2005
Keywords:kbADO210sp2fix kbbug kbDatabase kbDSupport kbMDAC210SP2fix KB190625