Remote Data Services

Remote Data Services (previously called Advanced Data Connector) is designed to address the limitation of static data in Web pages. 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.

Remote Data Services addresses this limitation by allowing you to remote a record set to the client computer. The remote record set stays alive and can be manipulated in the client computer. Remote Data Services allows you to use an ADO record set that has been generated from a remote server. The record set generated from the remote server can be marshaled to the client computer without a continuing active connection to the database server.

Remote Data Services is integrated into the ADO object model. Advanced Data Connector, shipped with OLE DB SDK version 1.1, provides mechanisms for disconnected record sets and client-side caching, enabling dynamic Web database programming.

Another concept introduced by Remote Data Services is the use of business objects. Remote Data Services also 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 OLE 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. 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 constantly changed without affecting any client computer.

Business objects are perfect for separating business rules from a 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 connection in a remote computer, business rules and data can be protected.

You can use the default AdvancedDataFactory business object to create a business object. The AdvancedDataFactory object provides the basic data read and write 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 record set.

Disconnecting a record set in a business object

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

You can create a disconnected record set 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, any updates for the disconnected record set are in a batch mode, and the client cursor is used to cache the unique identification for the record set.

The example shows how to create a disconnected record set:

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 record set, the client computer can use ADC controls or ADOR record sets to manipulate data. After the changes are made to the record set, the client computer can choose to marshal the whole record set back or only the changed data. The MarshalOptions property of the ADO record set is designed for this purpose. The following code can be placed in a Web page to retrieve a record set from a business object and marshal the record set back to the business object:

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

Reconnecting and applying changes

After the updated record set is marshaled back from the client computer, the business object can reconnect to the record set and use the UpdateBatch method to apply changes to the database server. The business object can reconnect to the record set 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