# Remote Data Binding with Remote Data Service

If your Web application provides clients with the ability to access data, you can distribute the processing of that data between the client and the server with Remote Data Service (RDS). Client-side RDS components send queries to the Web server. The server-side RDS components process these requests and send them to the Database Management System (DBMS) by use of a business object. The DBMS responds to the request, sending back the data to the Web server. The RDS components on the Web server transform that data into an ADO Recordset object. The data is parsed for transport to the client and sent back across the network to the client computer where it may be displayed in data-aware controls, such as a text or combo box.

The two main objects that you will use to accomplish remote data binding are RDS.DataControl and RDS.DataFactory. First, create a copy of the RDS.DataControl object on the client computer by inserting an object tag in an HTML page. For example:

    <OBJECT CLASSID="clsid:BD96C556-65A3-11D0-983A-00C04FC29E33" ID="RDSDC1">
       <PARAM NAME="SQL" VALUE="SELECT Author, ID FROM Authors">
       <PARAM NAME="CONNECT" VALUE="DSN=Pubs;">
       <PARAM NAME="SERVER" VALUE=http://Bookweb/>
    </OBJECT>

The preceding object tag creates an instance of the RDS.DataControl object and sets the SQL, Connect, and Server parameters for it. If you add this tag to an HTML page, you could then bind the data control object to multiple data-aware controls on the HTML page. For example, the following HTML tags display an HTML table that is bound to the above RDS.DataControl object.

    <TABLE id=Tasks DataSrc=#RDSDC1 WIDTH=100% BORDER=1 style="display: none">
    <THEAD ALIGN=left>
        <TR>
            <TH><em>ID</TH>
            <TH><em>Author</TH>
    </TR>
    </THEAD>
        <TR>
            <TD><DIV DATAFLD=ID></DIV></TD>
            <TD><DIV DATAFLD=Author></DIV></TD>
    </TR>
    </TABLE>

The object on the server that communicates with the RDS.DataControl object is either the RDS.DataFactory, or a business component. You can instantiate the RDS.DataFactory object by first creating a RDS.DataSpace object on the client, which then creates an instance of the DataFactory object on the server with the CreateObject method. The following example script demonstrates this process.

If your data access needs cannot be served by the RDS.DataFactory object, you can either a create a custom business component to communicate with the client, or you can use ADO directly from your ASP script to retrieve the data. In the following example, the custom business component, Inventory, exposes a method called getQuantityonHand. The RDS.DataControl object creates an instance of Inventory on the server, and then calls the getQuantityonHand method to retrieve records.

    <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 objInventory, myRS
      Set objInventory =
      ADS1.CreateObject("Company.Inventory", _
      "http://<%=Request.ServerVariables("SERVER_NAME")%>")
      ' Inventory exposes a method called
      ' getQuantityonHand that takes connection string and SQL parameters.
      Set myRS = objInventory.getQuantityonHand _
      ("DSN=pubs;UID=sa;PWD=permission;","Select Quantity From Inventory")
      ' Assign the returned recordset to SourceRecordset.
      ADC1.SourceRecordset = myRS
      End Sub
    </SCRIPT>
    </BODY>
    </HTML>

The same issues that are described in Component Design Guidelines, in the IIS documentation in the Platform SDK, apply to any custom data business components you create to communicate with RDS.DataControl. For example, you should make sure that the component supports either the Apartment or Both threading model.

Note Remote Data Service (RDS) replaces the Advanced Data Connector (ADC), which is now considered obsolete. In particular, the ADC remoting functionality (the ability to manipulate and modify sets of records on the client) has been integrated into ADO as RDS.

For more information, see the Remote Data Service documentation in the Platform SDK.

© 1997-2001 Microsoft Corporation. All rights reserved.