#1 2014-04-11 13:22:50

noobies
Member
Registered: 2011-09-13
Posts: 139

How display custom message and close programm when server is down?

Sample 04

  Form1.Database := TSQLHttpClient.Create(Server,'8080',Form1.Model);
  TSQLHttpClient(Form1.Database).SetUser('User','synopse');

if run in Delphi we see message Project Project04Client.exe raised exception class EWinHTTP with message 'Unable to connect to localhost:8080 - server may be down or unavailable'.
i try use terminate on except but nothing happends

  Form1.Database := TSQLHttpClient.Create(Server,'8080',Form1.Model);
  try
    TSQLHttpClient(Form1.Database).SetUser('User','synopse');
  except
    Application.Terminate;
  end;

How to verify that the server is down?

Last edited by noobies (2014-04-11 13:24:01)

Offline

#2 2014-04-11 20:21:49

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,207
Website

Re: How display custom message and close programm when server is down?

See the SAD 1.18 pdf about this, and also sample 16 for instance:

  fModel := TSQLModel.Create([],ROOT_NAME);
  fClient := TSQLHttpClient.Create('localhost',PORT_NAME,fModel);
  if not fClient.ServerTimeStampSynchronize then begin
    ShowLastClientError(fClient,'Please run Project16ServerHttp.exe');
    Close;
    exit;
  end;
  if (not fClient.SetUser('User','synopse'))  or
     (not fClient.ServiceRegisterClientDriven(TypeInfo(IRemoteSQL),fService)) then begin
    ShowLastClientError(fClient,'Remote service not available on server');
    Close;
    exit;
  end;

Trick is to execute ServerTimeStampSynchronize first, to check that the server is currently running.

Offline

Board footer

Powered by FluxBB