Step-By-Step Client/Server Tutorial

<< Click to Display Table of Contents >>

Navigation:  Apollo VCL Components > Installing and Using Apollo VCL >

Step-By-Step Client/Server Tutorial

This section provides the developer with a step-by-step tutorial on the minimal steps required to connect to a table through the Apollo Database Server. These steps assume that the Apollo VCL components have already been installed in the Delphi / C++Builder IDE. The SETUP program may have taken care of this automatically. If not, you will need to do so manually before continuing.

image\tip.gif Apollo Database Server support is not available under Delphi 3.x

Configuring the Apollo Database Server Application

1.Start the Apollo Database Server application (ApolloServer.exe). Leave the Server application running for the remainder of these steps.

image\server1-256.gif

Execute the Apollo Server Manager (ADSManager.exe, sometimes referred to as the " Server Manager") on the server PC. This can be the same PC that will be acting as the client, or a remote PC on a Windows-based network or on an Internet web server running a Windows-based web server. If you are running this from the same machine that the Apollo Database Server is running on, you can access this program from the Apollo Database Server's Tools menu.

image\login1-256.gif

In the Login dialog, type SYSDBA for User Name and masterkey for the Password. These are the initial defaults and can be changed later. For now, leave them as this for the tutorial.

2.From the " Manage Databases" tab page, you can create database Aliases to be referenced in the DatabaseName property of the TApolloTable component. For the Path, enter the physical drive and path where the tables will be located for this Alias. For Driver, select Clipper, FoxPro, or HiPer-SIx. A default example alias called SAMPLEDATA will already be entered referencing a ..\Server\SampleData subdirectory under the Server directory. (NOTE: A small table called TEST.DBF will have been installed in the same directory as the Server and Server Manager applications, and our client application in the tutorial steps below will be opening this table, so please insure that this step is followed correctly.)

3.From the "Server Settings" tab page, make note of the Port address value. This is the value that you will use in the client application for the Port property of TApolloConnection. By default, this should be set to 8121.

Connecting the Client to the Server Using TApolloQuery

1.In Delphi/C++Builder, start a new project by selecting "File | New Application" from the main menu.

2.From the Apollo page of the Component Palette, add one TApolloQuery and one TApolloConnection to the form.

3.On the TApolloConnection component, set the Host property to the IP address (ex: 127.0.0.1) or domain name (ex: www.mydomain.com) of the server PC. If this is your local machine, the IP address will be 127.0.0.1. Also set the Port property to the same value as the Server application's Port address. (NOTE: By default, the Server port address is set to 8121.)

4.For the User property, type SYSDBA and for the Password property, type masterkey. These are the same user account values that were defined in the Apollo Server Manager program earlier.

5.Now, note that the main form of the Server displays 0 (zero) for Active Sessions. Then, in the client project, set the TApolloConnection.Active property to True. If all goes well, you should see the Server display change to show 1 (one) active session.

image\tip.gif If the connection to the Server failed, check that the Port and IP address are set correctly.

4.Click on the TApolloQuery component to select it, connect the TApolloQuery to the TApolloConnection component by setting the ApolloConnection property to ApolloConnection1.

5.Now, click the DatabaseName property and note that the dropdown list reflects the Alias name(s) defined in the Server. Select SAMPLEDATA.

6.Click the ellipse button for the SQL property. This displays a standard TStrings property editor, which allows a free-form, multi-line SQL statement to be entered. For now, lets start with the simplest of SQL statements, enter: SELECT * FROM test, and close the window.

image\tip.gif In real world applications, the type of SQL expression listed above is not practical, since it is pulling all fields and all records from the table. For best performance in a real application, you would typically only request the minimal fields that you need for this task and would also use a WHERE clause to specify a query condition that a sub-set of the records must meet.

 

For example: SELECT first, last, age FROM test WHERE (age > 50), would only retrieve the first name, last name, and age fields from the table, and only from those records where the age field contained a value greater than 50.

7.Now, set the TApolloQuery.Active property to True. (NOTE: If you have not already noticed, all of these activities of selecting the Alias and table name and opening the table have all been reflected in the monitor window of the Server. Keep in mind that during normal operation, you would typically keep the Server monitor off to improve performance of the database operations.)

8.From the Data Access page, select one TDataSource component and drop it on the form. Set its DataSet property to ApolloQuery1.

9.Now, from the Data Controls tab of the Component Palette, select a TDBGrid control and drop it on the form. Set its DataSource property to DataSource1. You should see live data in the grid. This data is coming from through the Server.

Connecting the Client to the Server Using TApolloTable

1.In Delphi/C++Builder, start a new project by selecting "File | New Application" from the main menu.

2.From the Apollo page of the Component Palette, add one TApolloTable and one TApolloConnection to the form.

3.On the TApolloConnection component, set the Host property to the IP address (ex: 127.0.0.1) or domain name (ex: www.mydomain.com) of the server PC. If this is your local machine, the IP address will be 127.0.0.1. Also set the Port property to the same value as the Server application's Port address. Default Server port address is set to 8121.

4.For the User property, type SYSDBA and for the Password property, type masterkey. These are the same user account values that were defined in the Apollo Server Manager program earlier.

5.Now, note that the main form of the Server displays 0 (zero) for Active Sessions. Then, in the client project, set the TApolloConnection.Active property to True. If all goes well, you should see the Server display change to show 1 (one) active session.

image\tip.gif If the connection to the Server was unable to be made and you see an error dialog, make sure that the Port number and IP address are set correctly.

10.Click on the TApolloTable component to select it, and set the AccessMethod property to amServer. This tells the component to look through the TApolloConnection to the Server for the data, rather than to the local machine (amLocal).

11.Connect the TApolloTable to the TApolloConnection component by setting the ApolloConnection property to ApolloConnection1.

12.Now, click the DatabaseName property and note that the dropdown list reflects the Alias name(s) defined in the Server. Select SAMPLEDATA.

13.Click the TableName property and note that the available tables in the SAMPLEDATA alias. Select TEST.DBF.

14.Set the TApolloTable.Active property to True. (NOTE: Notice that all of these activities of selecting the Alias and table name and opening the table have all been reflected in the monitor window of the Server. Keep in mind that during normal operation, you would typically keep the Server monitor off to improve performance of the database operations.)

15.From the Data Access page, select one TDataSource component and drop it on the form. Set its DataSet property to ApolloTable1.

16.Now, from the Data Controls tab of the Component Palette, select a TDBGrid control and drop it on the form. Set its DataSource property to DataSource1. You should see live data in the grid. This data is coming from through the Server.

image\tip.gif Always close tables before the application closes (typically caught in the OnClose event of the main form). Not doing so may result in an Access Violation, since the connection to the server was cut.

See Also

Apollo VCL Tutorial, TApolloConnection, TApolloTable, TApolloQuery