Microsoft KB Archive/191575

= PRB: Chaptered Recordset from Parameterized Query Not Saved =

Article ID: 191575

Article Last Modified on 3/2/2005

-

APPLIES TO


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

-



This article was previously published under Q191575



SYMPTOMS
If you try to save a hierarchical recordset generated by a parameterized query to a file, the following error appears:

An unknown error has occurred.

Using ADO 2.5, the following error appears:

Parameterized hierarchical Recordset objects cannot be persisted.



STATUS
Saving a hierarchical recordset generated by a parameterized query is not supported. This behavior is by design.



Steps to Reproduce Behavior
 Start Visual Basic and from the File menu, select New Project. Set a reference to the Microsoft ActiveX Data Objects Library.  Paste the following code in the GENERAL section of the form: Const strFileName As String = "C:\Orders.rst"

Private Sub Form_Load Dim cnNWindSQL As New ADODB.Connection Dim rsCustomers As New ADODB.Recordset Dim rsOrders As ADODB.Recordset Dim strConn As String Dim strSQL As String

On Error Resume Next Kill strFileName On Error GoTo 0

strConn = "Provider=MSDataShape;" & _ "Data Provider=SQLOLEDB;" & _ "Data Source=scep;" & _ "Initial Catalog=NWindSQL;"

cnNWindSQL.CursorLocation = adUseClient cnNWindSQL.Open strConn, "sa", ""

If MsgBox("Use parameterized shape?", vbYesNo) = vbYes Then strSQL = "SHAPE {SELECT * FROM Customers} " & _ "AS Customers APPEND " & _ "({SELECT * FROM Orders WHERE CustomerID = ?} " & _                  "AS Orders RELATE CustomerID TO PARAMETER 0) " & _ "AS Orders" Else strSQL = "SHAPE {SELECT * FROM Customers} AS Customers " & _ "APPEND ({SELECT * FROM Orders} AS Orders " & _                  "RELATE CustomerID TO CustomerID) AS Orders" End If

With rsCustomers .Open strSQL, cnNWindSQL, adOpenStatic, _ adLockReadOnly, adCmdText Set rsOrders = !Orders.Value

If MsgBox("Retrieve all chapters?", vbYesNo) = vbYes Then While Not .EOF Debug.Print !CustomerID & " has " _ & rsOrders.RecordCount & " orders." .MoveNext Wend End If         .Save strFileName .Close End With

Set rsCustomers = Nothing cnNWindSQL.Close Set cnNWindSQL = Nothing

End Sub  Run the code. If you choose to execute the parameterized SHAPE command and try to save it, the following error appears:

An unknown error has occurred.

-or-

Parameterized hierarchical Recordset objects cannot be persisted.

 If you choose not to execute the parameterized SHAPE command, you can save the recordset to the C:\Orders.rst file.</li></ol>

<div class="references_section">