Microsoft KB Archive/818521

= FIX: Application Terminates When the Depth of SHAPE Command Child Recordset is Large =

Article ID: 818521

Article Last Modified on 5/17/2007

-

APPLIES TO


 * Microsoft Data Access Components 2.8
 * Microsoft ActiveX Data Objects 2.7

-



SYMPTOMS
When you increase the depth of the child recordset in a SHAPE command object by adding large number of recordsets, your application may quit unexpectedly.



CAUSE
The application quits unexpectedly because the relationship between the recordset is established recursively, and recursion depth is not controlled. When the uncontrolled recursion stack overflows, the application quits.



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 the Behavior
 Start Visual Basic 6.0. On the File menu, click New Project. In the New Project dialog box, click Standard Exe. By default, Form1 is created. On the Project menu, click References. Click Microsoft ActiveX Data Objects 2.7 Library and then click OK.  Double-click Form1 to open the code view for Form_Load. Add the following code to the Form1_Load event. Private Sub Form_Load Dim cn As New Connection Dim rs As New Recordset Dim str As String Dim shapestr1 As String Dim i As Integer

cn.Open &quot;Provider=MSDataShape;Data Provider=SQLOLEDB;User ID=sa;Persist Security Info=False;Initial Catalog=Northwind;Data source=10.150.144.131&quot; On Error Resume Next cn.Execute (&quot;DROP TABLE F1&quot;) cn.Execute (&quot;CREATE TABLE F1 (id INT PRIMARY KEY, name VARCHAR (255))&quot;) cn.Execute (&quot;INSERT INTO F1 (id, name) VALUES (1, '11111111111')&quot;) cn.Execute (&quot;INSERT INTO F1 (id, name) VALUES (2, '22222222222')&quot;) cn.Execute (&quot;INSERT INTO F1 (id, name) VALUES (3, '33333333333')&quot;) cn.Execute (&quot;INSERT INTO F1 (id, name) VALUES (4, '44444444444')&quot;) cn.Execute (&quot;INSERT INTO F1 (id, name) VALUES (5, '55555555555')&quot;) cn.Execute (&quot;DROP TABLE F2&quot;) cn.Execute (&quot;CREATE TABLE F2 (idx INT PRIMARY KEY, title VARCHAR (255))&quot;) cn.Execute (&quot;INSERT INTO F2 (idx, title) VALUES (1, '11111111111')&quot;) cn.Execute (&quot;INSERT INTO F2 (idx, title) VALUES (2, '22222222222')&quot;) cn.Execute (&quot;INSERT INTO F2 (idx, title) VALUES (3, '33333333333')&quot;) cn.Execute (&quot;INSERT INTO F2 (idx, title) VALUES (4, '44444444444')&quot;) cn.Execute (&quot;INSERT INTO F2 (idx, title) VALUES (5, '55555555555')&quot;) On Error GoTo ErrHandler Dim hapestr1 As String, shapestr2 As String ' Construct SHAPE command shapestr1 = &quot;SHAPE {select * from F1} APPEND (&quot;  shapestr2 = &quot;RELATE id TO id) &quot; For i = 2 To 11000 shapestr1 = shapestr1 + &quot;(SHAPE {select * from F1} APPEND (&quot; shapestr2 = &quot;RELATE id TO id)) &quot; + shapestr2 Next shapestr1 = shapestr1 + &quot;{select * from F1} &quot; shapestr1 = shapestr1 + shapestr2 ' Try to open the recordset rs.Open shapestr1, cn, adOpenDynamic, adLockBatchOptimistic, -1 rs.Close Exit Sub ErrHandler: MsgBox &quot;Error Number: &quot; & Err.Number MsgBox &quot;Error Description: &quot; & Err.Description End Sub  On the Run menu, click Start.

The application stops responding and the Visual Basic instance terminates automatically.

