Microsoft KB Archive/239941

= FIX: ADODB Jet 4.0 Recordset.Seek Causes Application Error on Recordset.Close =

Article ID: 239941

Article Last Modified on 5/17/2007

-

APPLIES TO


 * Microsoft ActiveX Data Objects 2.1
 * Microsoft ActiveX Data Objects 2.1 Service Pack 1
 * Microsoft ActiveX Data Objects 2.1 Service Pack 2
 * Microsoft ActiveX Data Objects 2.5

-



This article was previously published under Q239941



SYMPTOMS
Closing the Recordset after the Seek may result in the following error message:

Application Error - The Instruction at '0x--' referenced memory at '0x--'. The memory could not be written.



CAUSE
ADO is not properly releasing memory after freeing the fields collection on Recordset.Close.



RESOLUTION
Recordset.Seek works if there is no mix of syntax between multiple and single-index columns. For instance, if you use the following syntax: Recordset.Seek Array("12345"), adSeekFirstEQ Do not follow with this syntax: Recordset.seek Array("12345", "12"), adSeekFirstEQ



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

This problem is fixed in Microsoft Data Access Components 2.6 (MDAC 2.6). You may download the latest version of the Microsoft Data Access Components from the following Microsoft Web site:

http://msdn2.microsoft.com/en-us/data/aa937695.aspx



MORE INFORMATION
To reproduce this problem create a command button on the form, and paste the following code in the General Declarations section of a new Visual Basic Standard EXE project. Add a reference to the Microsoft ActiveX Data Object Library.

NOTE: This sample code is based on the NorthWind database converted to Access 2000 database format.

Option Explicit

Private Sub Command1_Click

On Error GoTo ErrorMessage

Dim adoCn As ADODB.Connection Dim adoRS As ADODB.Recordset Dim strCn As String

'Nwind Access97 database converted to Access2k. strCn = App.Path & "\Northwind2k.mdb" Set adoCn = New ADODB.Connection With adoCn .Provider = "Microsoft.JET.OLEDB.4.0" .Open strCn, "Admin", "" End With

Set adoRS = New ADODB.Recordset With adoRS Set .ActiveConnection = adoCn .CursorLocation = adUseServer .CursorType = adOpenKeyset .LockType = adLockPessimistic .Index = "PrimaryKey" .Open "Order Details", adoCn,, , adCmdTableDirect End With

'If you use the Seek String syntax before the Array you will get an Application Error. 'If you use the Array syntax first - no error. 'If you are consistent and use the String or Array syntax for both - no error.

'Uncomment either of these two lines below and you will get an Application Error. 'adoRS.Seek "10253", adSeekFirstEQ 'adoRS.Seek Array("10253"), adSeekFirstEQ adoRS.Seek Array("10253", "49"), adSeekFirstEQ Debug.Print adoRS.Bookmark

adoRS.Seek Array("10255", "16"), adSeekFirstEQ 'adoRS.Seek "10255", adSeekFirstEQ Debug.Print adoRS.Bookmark

Debug.Print "Success..." GoTo ExitSub

ErrorMessage: MsgBox Err.Number & " : " & vbCrLf & Err.Description

ExitSub: adoRs.Close adoCn.Close Set adoCn = Nothing Set adoRS = Nothing

End Sub

