Article ID: 183315
Article Last Modified on 3/14/2005
Public Function SumInt(FirstInt As Integer, _
SecondInt As Integer) As Integer
SumInt = FirstInt + SecondInt
End Function
Possible causes for failure could include the following:
\HKEY_LOCAL_MACHINE
\SYSTEM
\CurrentControlSet
\Services
\W3SVC
\Parameters
\ADCLaunch
Public Function ReturnRSValue(strConnect As String, _
strQuery As String) As Variant
Dim adoCon1 As New ADODB.Connection
Dim adoRs1 As New ADODB.Recordset
Dim x As Variant ' Variant array to send to the Client
' Open a connection to the Database.
adoCon1.Open strConnect
' Open an ADO Recordset.
adoRs1.Open strQuery, adoCon1, adOpenStatic, adLockBatchOptimistic
' Fill the Variant array using GetRows.
x = adoRs1.GetRows(adGetRowsRest, adBookmarkFirst)
' Return the Variant array to the Client.
ReturnRSValue = x
End Function<BR/>
Possible causes of failure could include the following:
Public Function ReturnRS(strConnect As String, _
strQuery As String) As ADODB.Recordset
Dim adoCon1 As New ADODB.Connection
Dim adoRs1 As New ADODB.Recordset
' Set the CursorLocation to adUseClient to return an
' ADORecordset to an RDS DataControl.
adoCon1.CursorLocation = adUseClient
' Open ADO Connection with passed in connect string.
adoCon1.Open strConnect
' Open ADO Recordset with passed in SQL string.
adoRs1.Open strQuery, adoCon1, adOpenKeyset, adLockBatchOptimistic
' Return ADO Recordset object to Client.
' (Returns the actual recordset not just a pointer to it).
Set ReturnRS = adoRs1
' Can not close the ADO Recordset object here,
' but it can be disassociated.
Set adoRs1.ActiveConnection = Nothing
' Close ADO Connection object.
adoCon1.Close
End Function
Public Function EnhancedSubmit(strConnect As String, _
rs As ADODB.Recordset, _
nPosted As Integer, _
vStatus() As Variant)
Dim i As Integer
Dim s As String
dim nConflict as integer
Dim r As New ADODB.Recordset
On Error GoTo ErrCond
s = ""
nPosted = 0
nConflict = 0
' Re-establish connection, submit changes &
' count # affected records
r.Open rs, strConnect
r.UpdateBatch adAffectAll ' Send in modifications
r.Filter = adFilterAffectedRecords '
nPosted = rs.RecordCount
' Determine if there are any conflicts and what type...
ReDim vStatus(r.RecordCount)
i = 0
r.MoveFirst
While r.EOF = False
vStatus(i) = r.Fields(0).value & ": "
CheckStatus r.status, vStatus(i)
' Only report back errors, not accepted or unmodified recs(!)
If (r.status <> adRecOK) And (r.status <> adRecUnmodified) Then
If Len(s) > 0 Then s = s & vbCrLf
s = s & vStatus(i)
nConflict = nConflict + 1
End If
r.MoveNext
i = i + 1
Wend
r.Close
Set r = Nothing
' Set message to return to client
If Len(s) = 0 Then
s = s & "Success! " & Str(nPosted) & " Records Posted."
Else
s = s & vbCrLf & _
"Attempted to Post " & Str(nPosted) & " Records, " & _
Str(nConflict) & " Conflicts Encountered(!)"
End If
EnhancedSubmit = s
Exit Function
ErrCond:
Select Case Err.Number
Case -2147217887 ' Raised when ALL records conflict
s = "Conflicts Occurred in UpdateBatch!"
Resume Next
Case Else
Test4_EnhancedSubmit = "FAILURE " & Str(Err.Number) & _
"--" & Err.Description
End Select
End Function
The CheckStatus subroutine mentioned in the preceding code above is provided in the RDS series of samples listed in the references section and builds a string based on the flags that are set in the Recordset.Status property. You can use this to see why a given record failed. A variation on this conflict resolution code is provided in the RDS* series of samples, as well as the RDSENSUB sample also listed below.
rs.MarshalOptions = adMarshalModifiedOnlyThis tells RDS to submit records only to the business object (custom or default) that are changed or added (and of course indicate any deletions that may have occurred). With your local client, as you are bypassing RDS, there is no marshalling; therefore, this property has no affect. The entire recordset is passed to the business object, not just the modified records.
183609 FILE: Rdsvb.exe Demonstrates How to Use RDS with Visual Basic
177720 FILE: Rdsensub.exe with RDS Conflict Resolution Sample
Keywords: kbhowto kbdatabase KB183315