Microsoft KB Archive/193093

= FIX: Setting Rst.ActiveConnection to a Recordset Causes GPF =

Article ID: 193093

Article Last Modified on 3/21/2005

-

APPLIES TO


 * Microsoft Data Access Components 1.5
 * Microsoft Data Access Components 2.0
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q193093



SYMPTOMS
Setting a Recordset's ActiveConnection property to a recordset object causes either a Dr. Watson or a general protection fault (GPF) error to occur. For example:

Set rst.ActiveConnection = rst



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

This problem has been fixed in MDAC version 2.1 Service Pack 2.

Under MDAC versions 2.1 Service Pack 2 and later, you will receive the following trappable error as expected:

Run-time error '3001': Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.



MORE INFORMATION
It is not recommended to set the ActiveConnection property to a recordset object. It is recommended that the Recordset's ActiveConnection property be set to an actual Connection object or connection string. The proper behavior is for Visual Basic to respond with a trappable error because ActiveX Data Objects (ADO) is expecting a connection string or object.

Steps to Reproduce Behavior
 Open a Standard .exe project in either Visual Basic 5.0 or Visual Basic 6.0. From the Project menu, choose References, and then select the Microsoft ActiveX Data Objects 2.0 or 1.5 Library.  Paste the following code into the form and enter the correct data source in the ConnectionString parameter of the connection object: Option Explicit Dim cnn As ADODB.Connection Dim rst As New ADODB.Recordset

Private Sub Form_Load Set cnn = New ADODB.Connection cnn.Provider = "sqloledb" cnn.Open "Data Source=;Initial Catalog=pubs;","sa",""

rst.ActiveConnection = rst 'This causes GPF or Dr. Watson error. rst.Open "Select * from Authors" End Sub  Run the project.

