BUG: Access Violation Occurs in ADO When You Close the Form and Run the Executable File (314746)



The information in this article applies to:

  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
  • Microsoft Visual Basic Professional Edition for Windows 6.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

This article was previously published under Q314746

SYMPTOMS

You receive an access violation in ADO under the following circumstances:
  1. Call the Debug.Print method on certain properties of the ADO Recordset object.
  2. Compile the project.
  3. Run the file as an executable (.exe) file.

CAUSE

This problem occurs because the compiler does not remove the Debug.Print statement correctly.

RESOLUTION

To resolve this problem, use one of the following methods:
  • Remove the Debug.Print statement from the code.
  • Store the property value in a variable.

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 Standard EXE project in Visual Basic.
  2. Add two CommandButton controls to the form. Specify the caption "Open Recordset" for Command1. Specify the caption "Close Application" for Command2.
  3. On the Project menu, click Reference, and then select the Microsoft ActiveX Data Object 2.x check box.
  4. Add the following code to the form:
    Option Explicit
    Dim cn As ADODB.Connection
    
    
    Private Sub Command1_Click()
        Dim rs As ADODB.Recordset
        Set rs = New ADODB.Recordset
        
        rs.Open "Select * from Customers", cn, adOpenDynamic, adLockBatchOptimistic
        
        Debug.Print "Update: " & rs.EOF
        
        rs.Close
        Set rs = Nothing
        
    End Sub
    
    Private Sub Command2_Click()
        Unload Me
    End Sub
    
    Private Sub Form_Load()
        Set cn = New ADODB.Connection
        cn.Open "User ID=sa;password=sa;Initial Catalog=pubs;Data Source=mySQLServer"
    End Sub
    					
  5. Modify the connection string as appropriate for your environment.
  6. Compile and run the executable file.
  7. Click Open Recordset.
  8. Click Close Application. Notice that an access violation occurs.
  9. To resolve this problem, use one of the following methods:
    • Comment out the Debug.Print line of code, and then repeat steps 5 through 7.
    • Replace the code
          Debug.Print "Update: " & rs.EOF
      							
      with the following code:
      Dim b as boolean
      b = rs.eof
      Debug.Print "Update: " & b
      						

Modification Type:MajorLast Reviewed:1/2/2002
Keywords:kbbug kbDSupport KB314746