Home arrow Delphi-Kylix arrow Page 2 - Using the Client Dataset in Two-Tiered Client/Server Applications

Using the Client Dataset in Two-Tiered Client/Server Applications

Client-server based applications have a number of advantages over file-based applications. To make such an approach work, however, the client dataset requires a provider component. This article will introduce you to the dataset provider component.

Author Info:
By: Danish Ahmed
Rating: 5 stars5 stars5 stars5 stars5 stars / 5
December 26, 2007
  1. · Using the Client Dataset in Two-Tiered Client/Server Applications
  2. · Two-Tiered Architecture
  3. · Using Data-Aware Components with the Client Dataset
  4. · Navigating and Modifying Data Programatically

print this article

Using the Client Dataset in Two-Tiered Client/Server Applications - Two-Tiered Architecture
(Page 2 of 4 )

A two-tiered client-server program is divided into two parts, a server and a client which interact with each other over a network. A data storage mechanism is implemented in the server, which allows the client to connect to itself and transact data. A server normally doesn't interact with the end user; it receives requests from the client application, processes them and sends a reply to the client application.

A client, on the other hand, interacts directly with the end user, usually through a graphical interface. It acts as an intermediary between the user and the server.

The two-tiered architecture is based on pretty simple logic, and for that reason it is best suited to performing simple tasks in environments with a small number of users. But even then, if the number of transactions is slightly larger, the network may be overloaded, thus degrading the performance. As I have said earlier, the client dataset component can be used to cache data locally and commit all changes to the server in a single transaction. Using the client dataset in a two-tiered application can help drastically reduce network traffic and enhance  performance. So let us take a look at how the client dataset can be used in a two-tier database application.

A distinctive feature of the client dataset is that by itself, it cannot connect to a database source and requires a TDataset Provider class to interact with the data source. The TClient Dataset component points to the dataset provider through its Provider Name property. You can link the client dataset to its dataset provider during design time by selecting the name of the instance of the TDataset Provider in the Object Inspector and during runtime, it can be specified in a single statement.



The dataset provider in its turn needs to point to another dataset which is linked to the database. This can be done by specifying the dataset's name in the "dataset" property of the dataset provider. When the client dataset is opened it sends a request to the dataset provider which opens the dataset pointing to the external data source, fetches data, converts it to data packets and closes the dataset. It then passes these data packets to the client dataset, which decodes them and loads them into memory, keeping the original structure intact. Another method which you can use to specify the provider to the client dataset is the SetProvider method.



This method can be called to link the client dataset to the dataset provider when the latter resides in the same application but has a different owner. In all other instances the Provider Name property should be used to associate the client dataset with the dataset provider.

In fact, the SetProvider method cannot be used when the provider resides in a remote module; further, the provider you intend to associate with the client dataset has to be a descendant of the TCustomProvider class or else an exception is raised. If you really have to use this method, do remember that this method associates the provider with the client dataset as long as it is open and the linkage is lost when the dataset is closed. So every time you open the client dataset you have to assign the provider using the same method. In contrast to using this method, assigning a provider to a client dataset using its ProviderName property is a much simpler and effective way.

The client dataset allows you to retrieve specific records from its internal and external providers by using its CommandText property. This property can be assigned an SQL statement, table name or stored procedure. When the dataset is opened or the Execute method is called and the CommandText property is not blank, the value held by it is sent to the server through the provider and the result set is sent back to the client dataset.

Do remember that the dataset provider's Option property should have poAllowCommandText set to true to send the CommandText value to the server. It should also be noted that any data held by the client dataset after it has been associated to a data source is replaced with the data retrieved by the execution of the CommandText.

blog comments powered by Disqus

- Loading an XML Document into the DOM
- Delphi Wrapper Classes and XML
- Delphi and the DOM
- Delphi and XML
- Internet Access: Client Service
- Finishing the Client for an Internet Access ...
- The Client for an Internet Access Control Ap...
- User Management for an Internet Access Contr...
- Important Procedures for an Internet Access ...
- Server Code for an Internet Access Control A...
- Constructing the Interface for an Internet A...
- Building a Server Application for an Interne...
- Building an Internet Access Control Applicat...
- Client Dataset: Working with Data Packets an...
- Using the Client Dataset in an N-Tiered Appl...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials