PRB: Child Recordset Submits Change w/o Active ConnectionID: Q215143
|
When the records in a child recordset of a hierarchical recordset are updated, the changes are committed to the database even when the ActiveConnection property of the child recordset is set to nothing. This problem does not affect the parent recordset. The parent recordset behaves correctly and does not issue the update to the database until the ActiveConnection is set to a valid connection.
NOTE: This problem does not occur if the hierarchical recordset is passed out-of-process.
Currently, the only workaround to this problem is to use the lock type of adLockBatchOptimistic and issue an UpdateBatch only when you are ready to commit the entries to the database. For local updates to the recordset you would use the Update method.
Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.
To reproduce this problem, follow the steps below. Please note that this code assumes that you are using the pubs database that ships with SQL Server. If you are using a different database, then you will need to change the SHAPE query to something that will return data from your database:
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim rsChild As ADODB.Recordset
Dim SQL As String
Dim Connect As String
Dim i As Integer
'This should be modified to point to your database
Connect = "Provider=MSDataShape;Driver={SQL Server};Database=pubs;Server=yourserver;UID=sa;PWD=;"
Set cn = New ADODB.Connection
With cn
.ConnectionString = Connect
.ConnectionTimeout = 15
.CursorLocation = adUseClient
.Open
End With
SQL = "SHAPE {SELECT pub_id, pub_name FROM publishers} " & _
"APPEND ({SELECT title_id, title, price, pub_id FROM titles} " & _
"AS TitlesRS RELATE pub_id TO pub_id)"
Set rs = New ADODB.Recordset
With rs
.CursorLocation = adUseClient
.Open SQL, cn, adOpenStatic, adLockBatchOptimistic
Set .ActiveConnection = Nothing
End With
cn.Close
'Get the child recordset
For i = 0 To rs.Fields.Count - 1
If (rs.Fields(i).Type = adChapter) Then
Set rsChild = New ADODB.Recordset
Set rsChild = rs.Fields(i).Value
End If
Next i
rs(1).Value = "TURTLE"
rsChild(1).Value = "TURTLE"
'The active connection is set to nothing on both of these objects so
'this should not be updated into the database ... the parent behaves
'correctly but the child does not.
rs.UpdateBatch
rsChild.UpdateBatch
rsChild.Close
rs.Close
Additional query words:
Keywords : kbADO200bug kbDatabase kbGrpVBDB
Version : WINDOWS:2.0,2.1,2.1 SP1
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: May 17, 1999