Board index » delphi » Checking "Connection Lost to Database"

Checking "Connection Lost to Database"

Hi
The below works but was looking for a more elegant way to check to see if
the database is connected.  Connected does not work if the server is
shutdown then restarted.

procedure TDM_Demon.VerifyDatabaseOpen;
(* If Server gets shut down then started up
again any query will bomb this routine reconnects*)
begin
  Try
    With qryTest Do (* query that brings no information back*)
      begin
        Open;
        Close;
      end;
  Except
    On E: Exception Do
      If (E.ClassName = 'EDBEngineError') and (E.Message = 'General SQL
error.'+ H_NEWLINE+'connection lost to database') Then
        begin
          DbDemon.Connected := False; (* Database disconnected but system
doesn't know it*)
          DbDemon.Open;  (* Gets a new database handle that the system
can use*)
        end;
  end;
end;
--
Cheers
Glenn Shukster of Gms Computing Inc.  Thornhill, Ont. Canada
Phone:(905)771-6458   Fax:(905)771-6819   http://members.home.net/gms
President of TDUG  http://www.tdug.com

 

Re:Checking "Connection Lost to Database"


To me it seems just fine. In fact, we use the same method.
Except in except block I do
    On E: EDBEngineError Do
       if E.Errors[E.ErrorCount-1].NativeError = -100 then begin
         aDB.Close;
        aDB.Open;
      end else raise;

Well, nativeError code is different for each server.
--
----------------------
Regards
Robert Cerny
Remove both qwe when replying
email: robert.qwe.ce...@neosys.xrs.qwe.si

No questions via email, unless explicitly invited.

Re:Checking "Connection Lost to Database"


Hi Robert
Glad to know I was on the right track.
Which database are you using?

In article <8clo05.d...@neosys.xrs.si>,
robert.qwe.ce...@neosys.xrs.qwe.si says...

Quote
> To me it seems just fine. In fact, we use the same method.
> Except in except block I do
>     On E: EDBEngineError Do
>        if E.Errors[E.ErrorCount-1].NativeError = -100 then begin
>          aDB.Close;
>         aDB.Open;
>       end else raise;

> Well, nativeError code is different for each server.
> --
> ----------------------
> Regards
> Robert Cerny
> Remove both qwe when replying
> email: robert.qwe.ce...@neosys.xrs.qwe.si

> No questions via email, unless explicitly invited.

Re:Checking "Connection Lost to Database"


Mostly db2 and sql anywhere. mssql is also good, but query optimizer has a
very strange logic, slightly better big mama sybase and never tried informix
nor oracle.
interbase is cool, compact, fast, but has somewhat rigid sql syntax.

--
----------------------
Regards
Robert Cerny
Remove both qwe when replying
email: robert.qwe.ce...@neosys.xrs.qwe.si

No questions via email, unless explicitly invited.

Quote
Glenn Shukster wrote in message ...
>Hi Robert
>Glad to know I was on the right track.
>Which database are you using?

Other Threads