PRB: ADO adMarshalModified Causes Problem with Late BindingID: Q229654 
  | 
Using disconnected recordsets in ADO, it is possible to encounter a problem when passing recordsets out of process to a custom business object for updating. The problem occurs when using the adMarshalModifiedOnly option before passing the recordset. If the client code uses late binding to the custom business object with the adMarshalModifiedOnly property, the recordset will be passed to the business object ByVal. In addition, it will be passed back to the client and overwrite the original recordset making any changes to the recordset by the business object visible to the client. Consequently, the client will only see the records that were marshalled to the business object, for example, only the modified rows. This problem does not occur if early binding to the business object.
There are two possible workarounds to this problem:
Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.
Below are the steps necessary to reproduce this problem. It is assumed that the reader will be running both the client and server components on the same machine. This code also makes use of the SQL Server pubs database.  You may need to alter the connection string and database query for your specific environment.
Private Sub Command1_Click()
    
    Dim rs As ADODB.Recordset
    Dim x As Long
    Const Connect = "Provider=MSDASQL.1;Persist Security Info=False;User ID=sa;Data Source=YOUR_DSN;Initial Catalog=pubs"
    Const Query = "SELECT * FROM AUTHORS"
        
    Debug.Print "--------EARLY BINDING-------------"
    Dim obj As ADOMarshalTest.Class1
    Set obj = New ADOMarshalTest.Class1
        
    Set rs = obj.Get_Disconnected_RS(Connect, Query)
    
    rs.MoveFirst
    rs(1).Value = "mike"
    rs(2).Value = "ruth"
    rs.Update
    
    rs.MarshalOptions = adMarshalModifiedOnly
    Debug.Print "Recordset Count Before Update: " & rs.RecordCount
    
    If (obj.UpdateBatchX(Connect, rs) <> 0) Then
        Debug.Print "ERROR ON UPDATE"
        Exit Sub
    End If
        
    Debug.Print "Recordset Count After Update: " & rs.RecordCount
    Set obj = Nothing
    
    Debug.Print "--------LATE BINDING-------------"
    Dim obj2 As Object
    Set obj2 = CreateObject("ADOMarshalTest.Class1")
    
    Set rs = obj2.Get_Disconnected_RS(Connect, Query)
    
    rs.MoveFirst
    rs(1).Value = "Mike"
    rs(2).Value = "Ruth"
    rs.Update
    
    'Comment this line to preserve the recordset on the client
    rs.MarshalOptions = adMarshalModifiedOnly
    
    Debug.Print "Recordset Count Before Update: " & rs.RecordCount
    
    If (obj2.UpdateBatchX(Connect, rs) <> 0) Then
        Debug.Print "ERROR ON UPDATE"
        Exit Sub
    End If
        
    Debug.Print "Recordset Count After Update: " & rs.RecordCount
End Sub 
Option Explicit
Public Function UpdateBatchX(ByVal szConnect As String, ByVal rs As ADODB.Recordset) As Long
    On Error GoTo errhandler
    
    Dim cn As ADODB.Connection
        
    Set cn = New ADODB.Connection
    With cn
        .ConnectionString = szConnect
        .ConnectionTimeout = 15
        .CursorLocation = adUseClient
        .Open
        
    End With
    
    With rs
        .ActiveConnection = cn
        .UpdateBatch adAffectAllChapters
        
    End With
    
    UpdateBatchX = 0
    Exit Function
errhandler:
    UpdateBatchX = Err.Number
    
End Function
Public Function Get_Disconnected_RS(ByVal szConnect As String, ByVal SQL As String) As ADODB.Recordset
    On Error GoTo errhandler
    Dim cn As ADODB.Connection
    Dim rs As ADODB.Recordset
    
    Set cn = New ADODB.Connection
    With cn
        .ConnectionString = szConnect
        .ConnectionTimeout = 15
        .CursorLocation = adUseClient
        .Open
        
    End With
    
    Set rs = CreateObject("ADODB.Recordset")
    rs.Open SQL, cn, adOpenStatic, adLockBatchOptimistic
    Set rs.ActiveConnection = Nothing
    Set Get_Disconnected_RS = rs
    Exit Function
errhandler:
    Set rs = Nothing
    Err.Raise Err.Number, "mrADOComponent..Get_Disconnected_RS", Err.Description
       
End Function For more information, please see the following article in the Microsoft Knowledge Base:
Q190717 INFO: Disconnected Recordsets with ADO or RDS
Additional query words:
Keywords          : kbADO kbDCOM kbMDAC kbRDS kbGrpVBDB kbGrpMDAC kbDSupport 
Version           : WINDOWS:1.5,2.0,2.1
Platform          : WINDOWS 
Issue type        : kbprb 
Last Reviewed: June 22, 1999