FIX: Access Violation Occurs in ADO When You Reopen a Recordset by Using adUseClient and adReadOnly Against MSDASQL (326834)



The information in this article applies to:

  • ActiveX Data Objects (ADO) 2.6
  • ActiveX Data Objects (ADO) 2.7

This article was previously published under Q326834

SYMPTOMS

When you call the Open method of an ADO client-cursor Recordset object that has been opened and closed previously, an access violation may occur if you change the LockType parameter of the method from adLockOptimistic to adLockReadOnly.

This problem only occurs with the Microsoft OLE DB Provider for ODBC (MSDASQL).

RESOLUTION

To resolve this problem, obtain the latest service pack for Microsoft Data Access Components (MDAC) 2.6. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

300635 INFO: How to Obtain the Latest MDAC 2.6 Service Pack

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 first corrected in Microsoft Data Access Components (MDAC) 2.6 Service Pack 2.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Create a new Standard EXE project in Visual Basic 6.0.
  2. On the Project menu, click References, and then click to select the Microsoft ActiveX Data Objects 2.6 Library check box or the Microsoft ActiveX Data Objects 2.7 Library check box.
  3. Add the following code to the Form_Load event:
    Dim cn As New Connection
    Dim rs As New Recordset
    
    cn.CursorLocation = adUseClient
    cn.Open "Provider=MSDASQL;Driver=SQL Server;server=(local);Trusted_Connection=Yes"
    Set rs.ActiveConnection = cn
    rs.Source = "Select * from sysobjects"
    rs.Open , , adOpenKeyset, adLockOptimistic
    rs.Close
    rs.LockType = adLockReadOnly
    rs.Open          'Access violation occurs here.
    MsgBox "Fixed"   'This message box appears only if you have the fixed version.
    					
  4. Save and then run your project. If you are using Microsoft Data Access Components (MDAC) 2.6 or 2.7, you receive an access violation.

Modification Type:MajorLast Reviewed:8/16/2002
Keywords:kbbug kbClient kbDSupport KB326834