Microsoft KB Archive/183294

= INFO: Techniques for Returning a Recordset Through RDS =

Article ID: 183294

Article Last Modified on 5/17/2007

-

APPLIES TO


 * Microsoft Remote Data Services 1.5
 * Remote Data Service for ADO 2.0
 * Microsoft Remote Data Services 2.1
 * Remote Data Service for ADO 2.5
 * Remote Data Service for ADO 2.6
 * Microsoft Remote Data Services 2.0
 * Microsoft Data Access Components 2.5
 * Microsoft Data Access Components 2.6
 * Microsoft Data Access Components 2.7

-



This article was previously published under Q183294



SUMMARY
There are several techniques for returning data in a disconnected recordset using the Remote Data Service (RDS). There are two objects on the client, the RDS.DataControl and RDS.DataSpace, and one object on a server, RDSServer.DataFactory, which you can manipulate in different ways to generate a recordset, and to submit changes made to the data it contains. The correct method for your application depends upon the design and functionality you want.



MORE INFORMATION
The Remote Data Service allows you to remote an ActiveX Data Objects (ADO) Recordset across HTTP, HTTPS or DCOM to a client computer. If using the HTTP/HTTPS protocal it assumes that you have a server running either Internet Information Server 3.0 (or greater), or Personal Web Server. In either case, you will have installed the RDS Server components on that server. The client computer requires the RDS components, and the client application can be written in any language that supports COM and manipulation of COM Objects (C++, Java, Visual Basic For Applications, VBScript, and so forth).

There are two types of ADO Recordsets that you see used in conjunction with RDS. The ADODB recordset comes from Msado15.dll, and is part of the entire ADO object hierarchy. However, when marshalling a recordset across the wire, in order to provide a thin client, (minimal DLL's and memory footprint), RDS converts that recordset into an ADOR recordset. ADOR (from Msado15r.dll) comes without the rest of the ADO object model. For the purposes of this discussion (as well as any code you write) ADOR.Recordset and ADODB.Recordset are synonymous. You should reference ADOR.Recordset in your client application and whether you use ADOR.Recordset or ADODB.Recordset in your server-side custom business object is irrelevant. However, if you use ADODB, you can use the Connection and Command objects which offer functionality not available just opening a recordset "stand- alone."

Technique #1 - The DataControl
You can use the RDS.DataControl to retrieve a recordset from the RDS Server via the Refresh method. You could also assign an existing recordset to the SourceRecordset property.

Within the Active Server Pages page (ASP) environment, you can bind graphical controls to the RDS.DataControl.

Whether in ASP or any other development environment, you can easily use the RDS.DataControl programmatically to retrieve, sort, and filter data. Most of the properties and methods of the DataControl resemble a subset of the ADO Recordset (either ADOR or ADODB.) The RDS.DataControl also offers asynchronous processing that is currently not offered within ADO 1.5. With the release of ADO 2.0 asynchronous processing is available.

The RDS.DataControl uses a business object on the server, provided by RDS, called the RDSServer.DataFactory. The DataFactory generates a recordset and also receives changes made to the data it contains. You cannot override (directly) the DataControl to use a different business object.

The following code demonstrates this technique using Visual Basic for Applications: Dim dc As RDS.DataControl

Set dc = New RDS.DataControl ' ASP Set dc = CreateObject("rds.datacontrol") dc.Connect = "DSN=RDSDemo;UID=admin;PWD=;" dc.SQL = "SELECT * FROM Authors" dc.Server = "http://" dc.ExecuteOptions = adcExecAsync dc.Refresh While dc.ReadyState = 2 DoEvents            ' User has control during asynchronous query. Wend NOTE: Starting with RDS 2.0, the functionality of the RDS DataFactory may be enhanced by writing a custom handler object that implements a specific interface called IDataFactoryHandler. For more information, please see ADO Help for the topic "Handler Property (RDS)."

Technique #2 - Using the DataSpace with the Default Business Object
You may use the RDS.Dataspace object to invoke a business object on the server. If you provide the ProgID of the default business object (RDSServer.DataFactory), then you use the business object that RDS provides for you. This business object can provide a Recorsdet, but offers no conflict resolution (or any information) regarding a failure if the changes you post to the data are not accepted.

The following code demonstrates this technique using VBA: Dim ds  Dim df   dim rs

Set ds = CreateObject("RDS.DataSpace") Set df = ds.CreateObject("RDSServer.DataFactory", _                           "http://" ) Set rs = df.Query("DSN=RDSDemo;UID=admin;PWD=;", _                    "SELECT * FROM Authors")

Technique #3 - Using the DataSpace to a Custom Business Object
A business object is nothing more than an ActiveX DLL registered on the RDS Server (and perhaps on the client, if you are using DCOM as your protocol). The advantage of this technique is that you can implement conflict resolution, data validation or other functionality within your business object.

There are three protocols you can use to marshall a recordset to the client, HTTP, HTTPS, and DCOM.

When using a custom business object you must add a registry setting to the server where the business object is registered. In the following example the VBCustBusObj.OBJ would need to be added to the following registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services \W3SVC\Parameters\ADCLaunch\VBCustBusObj.OBJ Consult the RDS Online documentation for details about registry settings that may be required for any custom business object.

The following code demonstrates this technique using VBA: Dim ds  Dim bo   dim rs

Set ds = CreateObject("RDS.DataSpace") Set bo = ds.CreateObject("VBCustBusObj.OBJ", _                           "http://") Set rs = bo.Test3_ReturnRS("DSN=RDSDemo;UID=admin;PWD=;", _                             "SELECT * FROM Authors")

Technique #4 - Using the MS Remote Provider
Starting with RDS 2.0, you can use the MS Remote provider along with standard ADO code to return an RDS recordset. The advantage is that you may use ADO code similar to the code you would use with any other provider; the only difference is the connection string. Although your code looks like ADO, it is actually using RDS. So, you must use clientside recordsets with the MS Remote provider.

The connection string for the MS Remote provider must specify the following: Provider       MS Remote

Remote Server  Server that you want to process your requests

Remote Provider Provider that you want the server to use (The default is the OLE DB Provider for ODBC) The following code demonstrates this technique using VBA: Dim cn    Dim rs

Set cn = CreateObject("ADODB.Connection") Set rs = CreateObject("ADODB.Recordset") cn.Open "Provider=MS Remote;Remote Provider=MSDASQL;" & _ "Remote Server=http:// ;" & _ "DSN=RDSDemo;UID=admin;PWD=;"

rs.CursorLocation = adUseClient rs.Open "SELECT * FROM Authors", cn

