Microsoft KB Archive/314746

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

Article ID: 314746

Article Last Modified on 1/2/2002

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft ActiveX Data Objects 2.1
 * Microsoft ActiveX Data Objects 2.5
 * Microsoft ActiveX Data Objects 2.6
 * Microsoft ActiveX Data Objects 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.



Steps to Reproduce Behavior
 Create a new Standard EXE project in Visual Basic. Add two CommandButton controls to the form. Specify the caption &quot;Open Recordset&quot; for Command1. Specify the caption &quot;Close Application&quot; for Command2. On the Project menu, click Reference, and then select the Microsoft ActiveX Data Object 2.x check box.  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 &quot;Select * from Customers&quot;, cn, adOpenDynamic, adLockBatchOptimistic Debug.Print &quot;Update: &quot; & 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 &quot;User ID=sa;password=sa;Initial Catalog=pubs;Data Source=mySQLServer&quot; End Sub  Modify the connection string as appropriate for your environment.</li> Compile and run the executable file.</li> Click Open Recordset.</li> Click Close Application. Notice that an access violation occurs.</li> To resolve this problem, use one of the following methods: <ul> Comment out the Debug.Print line of code, and then repeat steps 5 through 7.</li>  Replace the code Debug.Print &quot;Update: &quot; & rs.EOF with the following code: Dim b as boolean b = rs.eof Debug.Print &quot;Update: &quot; & b                       </li></ul> </li></ol>

Keywords: kbbug kbnofix KB314746

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.