DataSnap sample (Delphi)

Overview

This sample illustrates the use of different DataSnap modules (TRODataSnapModule instance) simultaneously in the server application and the use of the TRODataSnapConnection class in the client application. The sample includes a standalone version of the server, as well as the same server implemented as an ISAPI dll.

Prerequisites

The sample uses the Northwind database, which is available on the localhost server with Windows credentials. If you need to adjust your DB connection settings, open the DataSnapServerData/DataSnapServerData2 form, select the TADOConnection component and click 'Build':

Getting Started

  • Build all the projects in the project group.
  • Run DataSnapServer.exe and DataSnapClient.exe.
  • Click Connect on the client and see the data from the DB.

  • Make some changes to the data and apply the updates.
  • Close the server.
  • Now try the dll server: Place DataSNapIsapiServer.dll in the appropriate directory on IIS and comment/uncomment the following lines in DataSnapClientMain.pas:
 //HTTPChannel.TargetURL := 'http://localhost:81/bin';
 HTTPChannel.TargetURL := 'http://localhost/DataSnapIsapiServer.dll/bin';
  • With a dll server, it is also necessary to use SQL server authentication, not Windows. Set the user name and password in the TADOConnection component settings.
  • Run the client, connect to the DB, make some changes and apply the updates again.

Examine the Code

  • Look at DataSnapServerInterfaces.pas, where new interfaces descended from IAppServer are declared.
type
  IAppServer1 = interface(IAppServer)
  end;

  IAppServer2 = interface(IAppServer)
  end;
  • Look at DataSnapServerData.pas and DataSnapServerData2.pas and examine how we use the interfaces mentioned above.
TDataSnapServerDataForm = class(TRODataSnapModule,IAppServer1)
    con_SqlServer: TADOConnection;
    qry_customers: TADOQuery;
    prv_customers: TDataSetProvider;
    qry_customersCustomerID: TWideStringField;
    qry_customersCompanyName: TWideStringField;
    qry_customersContactName: TWideStringField;
    qry_customersContactTitle: TWideStringField;
    qry_customersAddress: TWideStringField;
    qry_customersCity: TWideStringField;
    qry_customersRegion: TWideStringField;
    qry_customersPostalCode: TWideStringField;
    qry_customersCountry: TWideStringField;
    qry_customersPhone: TWideStringField;
    qry_customersFax: TWideStringField;
  private
    { Private declarations }
  public
    { Public declarations }
  end;
  • Look at DataSnapClientMain.pas and examine how we use these interfaces with the TRODataSnapConnection.