#1 2011-07-19 08:08:14

corchi72
Member
Registered: 2010-12-10
Posts: 232

how to test the server connection before execute the client http

Hi,
  if i execute the connection with the server that is not started, i have a exception.

procedure LoadClientDatabase(var ClientDB: TSQLRestClientDB; ServerName: string; Port: Integer);
begin
  try
    Model := GetDatabaseModel('root');
    ClientDB := TSQLRestClientDB(TSQLite3HttpClient.Create(ServerName, IntToStr(Port), Model));
  except
    //on E: Exception do
    // handle initialization error here
  end;
end;

Can I avoid the exception and perform a test to see if the server is reachable or started?

thanks corchi

Offline

#2 2011-07-19 11:07:42

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

Re: how to test the server connection before execute the client http

What's wrong with the exception?
Just intercept it  in the except clause.

In your code, you're typecasting a TSQLite3HttpClient into a TSQLRestClientDB, and those two types are not compatible.

You should use the generic common ancestor TSQLRestClient or TSQLRestClientURI instead.

If you are not sure about the type, don't use forced typecast, but uses the "as" statement:

TSQLite3HttpClient.Create(....) as TSQLRestClientDB

It will raise an exception if the typecast is not correct.

I use forced typecast in my code only when I'm sure that the types are correct.

Offline

Board footer

Powered by FluxBB