Microsoft KB Archive/240341

= FIX: Creating Fabricated Hierarchical Recordset Fails Using MDAC 2.1SP2 =

Article ID: 240341

Article Last Modified on 5/17/2007

-

APPLIES TO


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

-



This article was previously published under Q240341



SYMPTOMS
When trying to create a fabricated (programmatic) hierarchical recordset using MDAC 2.1 SP2 (build 4202), the following error is generated:

Run-Time error '-2147467259 (80004005)': Unspecified error

This error occurs on the line that sets the child recordset to the child chaptered command. This line of code might look like:

Set rsChild = rsParent("ChildCommand").Value where:

rsChild is the the child recordet, rsParent is the parent recordset, ChildCommand is the child chaptered command.



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



RESOLUTION
If you are using ADO 2.1 sp2 (build 4202), there is a workaround for this bug; simply add a line of code that sets the ActiveConnection of the parent recordset to Nothing. Your code might look like this: .........

Set rsParent.ActiveConnection = Nothing Set rsChild = rsParent.Fields("ChildCommand").Value

.........



STATUS
Previous releases of MDAC 2.1 did not have this problem.

This bug was corrected in Microsoft Data Access Components 2.5 (MDAC 2.5) and later.

You can download the latest version of Microsoft Data Access Components from the following Microsoft Web site:

http://msdn2.microsoft.com/en-us/data/aa937695.aspx



Steps to Reproduce Behavior

 * 1) Start a new project in Visual Basic and select Standard EXE. Form1 is created by default.
 * 2) At the Visual Basic project, reference the following object library: Microsoft ActiveX Data Objects Library.
 * 3) Double-click Form1 to open Form1's Code Window.

Dim RS As New Recordset Dim SubRS As Recordset RS.LockType = adLockBatchOptimistic RS.Open "SHAPE APPEND NEW adInteger as RecordID, " + _ "NEW adVarchar(20) as RecordData, " + _ "((SHAPE APPEND NEW adInteger as RecordID, " + _ "NEW adVarchar(20) as SubRecordData" + _ ") Relate RecordID to RecordID) as SubRecord", _ "Provider=MSDataShape;Data Provider=None" RS.AddNew RS!RecordID = 1 RS!RecordData = "Test Record Data" Set SubRS = RS!SubRecord.Value ' Error occurs here SubRS.AddNew SubRS!RecordID = 1 SubRS!SubRecordData = "Test Subrecord Data" SubRS.AddNew SubRS!RecordID = 2 SubRS!SubRecordData = "Another Subrecord" Run.

Under MDAC version 2.1 sp2, the error is raised.

