BUG: Error Message "Rows Must Be Released" with SQLOLEDB and ADO Recordset Events (257731)



The information in this article applies to:

  • Microsoft Data Access Components 2.1
  • Microsoft Data Access Components 2.5
  • Microsoft Data Access Components 2.6
  • Microsoft Data Access Components 2.7
  • Microsoft Visual Basic Professional Edition for Windows 6.0
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0

This article was previously published under Q257731

SYMPTOMS

If a user opens an ActiveX Data Object (ADO) recordset by using the OLE DB Provider for SQL Server, sets the CursorLocation property to adUseServer, uses the WithEvents keyword, updates the same record more than once, and then executes a Move method such as MoveNext, the following error message appears

in MDAC versions 2.5 and later:
80040e25: Row handles must be released before new ones can be obtained
in prior MDAC versions:
All HROWs must be released before new ones can be obtained

RESOLUTION

This error message can be avoided in one of the following ways:
  • Using a CursorLocation property of adUseClient.

    -or-

  • Implementing code that moves off the changed record after each Update (for example, a MoveNext and MovePrevious method pair).

    -or-

  • Executing the Requery method of the Recordset after each Update.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a new Visual Basic Standard EXE project in Visual Basic. Form1 is created by default.
  2. Set a reference to Microsoft ActiveX Data Objects (ADO).
  3. Enter the following code into Form1's Code Window. Modify the ConnectionString to connect to your SQL Server:

    Note You must change User ID=<username> and Password=<strong password> to the correct values before you run this code. Make sure that the User ID has the appropriate permissions to perform this operation on the database.
    Option Explicit
    Dim WithEvents rs As ADODB.Recordset
    
    Private Sub Form_Load()
      Dim cn As ADODB.Connection
      Set cn = New ADODB.Connection
      With cn
        .ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=<username>;Password=<strong password>;Initial Catalog=pubs;Data Source=servername;"
        .CursorLocation = adUseServer
        .Open
      End With
      Set rs = New ADODB.Recordset
      With rs
      Set rs.ActiveConnection = cn
        .CursorLocation = adUseServer
        .CursorType = adOpenDynamic
        .Open "select * from Authors", cn, adOpenDynamic, adLockOptimistic
        .Fields("au_lname").Value = "footfoot1"
        .Update
        .Fields("au_lname").Value = "footfoot2"
        .Update
        .MoveNext
      End With
    End Sub
  4. Run the code. Note the error raised on the .MoveNext method.

Modification Type:MajorLast Reviewed:12/3/2003
Keywords:kbBug kbDatabase kbpending KB257731