Remote Data Service

Remote Data Service (RDS), which is integrated into the ADO object model, is designed to address the limitation of static data in Web pages. It shipped with OLE DB SDK and provides mechanisms for disconnected Recordset objects and client-side caching, enabling dynamic Web database programming. Traditional Web database technology allows you to retrieve data from a database server, but after the data is retrieved and displayed in a Web page, it becomes static and cannot be manipulated without establishing a new connection to the database server.

RDS addresses this limitation by allowing you to remote a Recordset to the client computer. Because the remote Recordset is live, you can manipulate it on the client computer. RDS allows you to use an ADO Recordset that has been generated from a remote server. The Recordset generated from the remote server can be marshaled to the client computer without a continuing active connection to the database server.

RDSRDS also introduces the concept of business objects. RDS allows you to partition your business rules from data. Instead of putting all the programming or business logic in the client Web page, you can put all the programming or business logic in a business object.

The Business Object and ADO

Business objects are DLLs or executables created by Visual Basic, Visual C++, or Microsoft Visual J++®. The idea of business objects is to partition application logic and business rules and to protect business rules and data from redistribution at the client. For example, a business rule can be rules for calculating the price of an airline ticket. The airline company does not want customers to know how the ticket price is calculated and may want to change the rules for calculating the price at any time. Ideally, this kind of business rule should be in a remote computer where the client has no knowledge of its logic and the rule can be changed without affecting any client computer.

Business objects can exist in a remote server and be invoked by the client computer. With only the necessary application logic in the client computer and all the business rules and database connections in a remote computer, business rules and data can be protected.

You can use the default RDSServer.DataFactory business object to create a business object. The DataFactory object provides the basic ability to read and write data, but nothing else. The ADO object model is another alternative for implementing business objects. ADO objects provide not only comprehensive data manipulation, but also the mechanism for remoting a Recordset.

Disconnecting a Recordset in a Business Object

Before remoting a Recordset, the Recordset has to be able to function as a Recordset object without a live connection to the database server. After a Recordset is marshaled to a client computer, the data connection cannot be and is not marshaled with the Recordset; therefore, the Recordset must be disconnected from the database server. A Recordset without a live connection to a database server is called a disconnected Recordset.

You can create a disconnected Recordset using the CursorLocation Recordset object property. The CursorLocation property allows you to specify whether to use client or server cursors and, most importantly, allows changes to be made in a batch mode. With adUseClient specified for the CursorLocation property, make any updates for the disconnected Recordset in a batch mode, and use the client cursor to cache the unique identification for the Recordset.

The following example demonstrates how to create a disconnected Recordset:

Public Function GetData() As Object
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
cn.Open "dsn=testing;uid=sa;pwd=;"
rs.CursorLocation = adUseClient
rs.Open "select * from authors for browse", cn, adOpenUnspecified, adLockUnspecified, adCmdUnspecified
Set GetData = rs
End Function

Marshaling Remote Changes Back to the Business Object

After the client computer receives the disconnect Recordset, the client computer can use RDS controls or ADOR Recordset objects to manipulate data. After the changes are made to the Recordset, the client computer can choose to marshal the whole Recordset back or only the changed data. The MarshalOptions property of the ADO Recordset is designed for this purpose. You can place the following code in a Web page to retrieve a Recordset from a business object and marshal the Recordset back to the business object:

Set rs = BusObj.GetData
Adc1.recordset=rs
' update data in controls or through ADOR recordset
set rso = adc.recordset
rso.MarshalOptions=1
BusObj.SetData rso

Reconnecting and Applying Changes

After the updated Recordset is marshaled back from the client computer, the business object can reconnect to the Recordset and use the UpdateBatch method to apply changes to the database server. The business object can reconnect to the Recordset using the Open method, as shown in the example:

Public Function SetData(rso As Object)
Dim rs As New ADODB.Recordset
rs.Open rso, "dsn=pubs;uid=sa"
rs.UpdateBatch
End Function