Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

FIX: Access ODBC Keyset Cursor Becomes Corrupt After a Delete


View products that this article applies to.

Symptoms

After deleting a row and doing a MoveNext or MovePrevious, the current record is wrong.

Exhibited behavior indicates that the current record will either become another record from within the recordset or EOF depending on the size of the recordset.

↑ Back to the top


Cause

A bug was introduced in MDAC 2.1 affecting the behavior of the Access ODBC Driver keyset cursors.

↑ Back to the top


Resolution

To resolve this problem, upgrade to MDAC 2.1 Service Pack 2 or MDAC 2.5 or later. These versions of MDAC can be obtained from the download section at the following Microsoft Web site:

↑ Back to the top


Status

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

This problem was corrected in MDAC 2.1 SP2.

↑ Back to the top


More information

The specific MDAC 2.1 DLL causing the problem is odbcjt32.dll.

Version 4.0.3513.00 shipped with MDAC 2.1 that was included with SQL Server 7.0.

Version 4.0.3711.08 of odbcjt32.dll shipped with MDAC 2.1 SP1.

MDAC 2.1 SP1 has shipped with Office 2000 and is downloadable at the MDAC Web site.

The following Visual C++ code in conjunction with the Microsoft sample Northwind database can be used to illustrate the behavior. It assumes that you used the MFC AppWizard to generate a CRecordset-derived class that wraps the Order Details table in nwind.mdb. The recordset must be opened as a CRecordset::dynaset to reproduce the problem:

   CDBwindSet rs;

   rs.Open();
   rs.m_pDatabase->BeginTrans();
   rs.MoveNext();
   rs.Delete();
   rs.MoveNext();  //You are now on the wrong record
   rs.m_pDatabase->Rollback();
   rs.Close();
				
The following Visual Basic code in conjunction with the Microsoft sample Northwind database can be used to illustrate the behavior. The cursor type needs to be adOpenDynamic. ADO will degrade to a keyset cursor because the Access ODBC driver does not support dynamic cursors.

It appears that setting the ADO recordset property CacheSize to something other than 1 (the default) causes the bug to not appear:
   Dim cnNorthwind As ADODB.Connection 
   Dim rsOrderDetails As ADODB.Recordset

   Private Sub Form_Load()
       Dim strConn As String
       Dim strSQL As String
       
       strConn = "Provider=MSDASQL;Driver={Microsoft Access Driver (*.mdb)};DBQ=c:\temp\NWind.MDB;"
       strSQL = "SELECT * FROM [Order Details] ORDER BY OrderID, ProductID"
       
       Set cnNorthwind = New ADODB.Connection
       cnNorthwind.Open strConn
       cnNorthwind.BeginTrans
       
       Set rsOrderDetails = New ADODB.Recordset
       rsOrderDetails.Open strSQL, cnNorthwind, adOpenDynamic, adLockOptimistic, adCmdText
       
       rsOrderDetails.MoveNext
       MsgBox "Row 2 = " & rsOrderDetails!OrderID & " - " & rsOrderDetails!ProductID
       rsOrderDetails.MoveFirst
       rsOrderDetails.Delete
       rsOrderDetails.MoveNext

       'Note you expect to be on Row 2 as before but you are not
       MsgBox "Row 2 = " & rsOrderDetails!OrderID & " - " & rsOrderDetails!ProductID
       rsOrderDetails.Close
       cnNorthwind.RollbackTrans
       cnNorthwind.Close
   End Sub
				

↑ Back to the top


Keywords: KB230131, kbqfe, kbmdac250fix, kbmdac210sp2fix, kbjet, kbfix, kbbug, kbqfe, kbhotfixserver

↑ Back to the top

Article Info
Article ID : 230131
Revision : 9
Created on : 9/22/2005
Published on : 9/22/2005
Exists online : False
Views : 357