The following client Microsoft® Visual Basic®, Scripting Edition code performs the same action as the previous RDSServer.DataFactory code, except that it uses a custom business object. You still use the RDS.DataSpace object on the client to create an instance of the business object (in this case, MyCustomBusinessObject) on the server.
<HTML>
<HEAD></HEAD>
<BODY>
<!-- RDS.DataControl -->
<OBJECT classid="clsid:BD96C556-65A3-11D0-983A-00C04FC29E33" ID=ADC1>
</OBJECT>
<!-- RDS.DataSpace -->
<OBJECT ID="ADS1" WIDTH=1 HEIGHT=1
CLASSID="CLSID:BD96C556-65A3-11D0-983A-00C04FC29E36">
</OBJECT>
.
.
.
<SCRIPT LANGUAGE="VBScript">
Option Explicit
Sub GetRecords()
Dim objMyCustomBusinessObject, myRS
Set objMyCustomBusinessObject = _
ADS1.CreateObject("MyCustomBusinessObject", _
"http://<%=Request.ServerVariables("SERVER_NAME")%>")
' Assume MyCustomBusinessObject has a method called
' GetData that takes connection string and SQL
' parameters.
Set myRS = _
objCustomBusinessObject.GetData _
("DSN=pubs;UID=sa;PWD=permission;", _
"Select * From Authors")
' Assign the returned recordset to SourceRecordset.
ADC1.SourceRecordset = myRS
End Sub
</SCRIPT>
</BODY>
</HTML>
Assuming you use Visual Basic to create the MyCustomBusinessObject ActiveX DLL that is located on the middle tier, the code in the GetData method of the MyCustomBusinessObject class could look something like this. Notice that you can use ActiveX® Data Objects (ADO) directly.
' Returns an ADO resultset.
Public Function GetData(szCnStr As String, szSQL _
As String) As Object
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
cn.Open szCnStr
' The ADODB.Recordset should generate Recordset
' objects that can be disconnected and later
' reconnected to process batch updates.
rs.CursorLocation = adUseClientBatch
' Using the Unspecified parameters, an ADO/R
' recordset is returned.
rs.Open szSQL, cn, _
adOpenUnspecified, adLockUnspecified, _
adCmdUnspecified
Set GetData = rs
End Function
Tips