Subject | Re: [IBO] How to reconnect to DB |
---|---|
Author | bluehorse@digitus.cz |
Post date | 2003-12-16T15:38:39Z |
Thanks,
event, seems like it could do the job and possibly reconnect to the
database, except that calling Disconnect, ForceDisconnect or
DisconnectToPool on line 17 displays an error dialogue 'Dataset is
currently fetching'. This is bad.
1 procedure TFormData.Database1Error(Sender: TObject;
2 const ERRCODE: Integer; ErrorMessage, ErrorCodes: TStringList;
3 const SQLCODE: Integer; SQLMessage, SQL: TStringList;
4 var RaiseException: Boolean);
5
6 const
7 boFlag : Boolean = False;
8
9 begin
10
11 RaiseException := True;
12 if boFlag then exit;
13
14 boFlag := True;
15 if ERRCODE = 335544721 then //connection might be lost
16 try
17 Database1.Disconnect;
18 Database1.Connect;
19 RaiseException := False;
20 except
21 end;
22
23 boFlag := False;
24
25 end;
(The boFlag static variable shall prevent calling the handler over
and over when Connect fails, seems this is not necessary when
calling DisconnectToPool...) The ERRCODE 335544721 was discovered
empiricaly I have no idea if this is a 100% correct approach.
Any idea how to make the whole process smoother without the 'Dataset
is currently fetching' dialog while disconnecting?
Andreas
> >Please, how to reconnect to the DB again, how to realize thethe
> >connection has been lost meanwhile?
>
> Listen for the exception. Write a handler that can be called from
> OnError event when this exception is detected.Well I tried to provide following code for the TIBODatabase.OnError
>
event, seems like it could do the job and possibly reconnect to the
database, except that calling Disconnect, ForceDisconnect or
DisconnectToPool on line 17 displays an error dialogue 'Dataset is
currently fetching'. This is bad.
1 procedure TFormData.Database1Error(Sender: TObject;
2 const ERRCODE: Integer; ErrorMessage, ErrorCodes: TStringList;
3 const SQLCODE: Integer; SQLMessage, SQL: TStringList;
4 var RaiseException: Boolean);
5
6 const
7 boFlag : Boolean = False;
8
9 begin
10
11 RaiseException := True;
12 if boFlag then exit;
13
14 boFlag := True;
15 if ERRCODE = 335544721 then //connection might be lost
16 try
17 Database1.Disconnect;
18 Database1.Connect;
19 RaiseException := False;
20 except
21 end;
22
23 boFlag := False;
24
25 end;
(The boFlag static variable shall prevent calling the handler over
and over when Connect fails, seems this is not necessary when
calling DisconnectToPool...) The ERRCODE 335544721 was discovered
empiricaly I have no idea if this is a 100% correct approach.
Any idea how to make the whole process smoother without the 'Dataset
is currently fetching' dialog while disconnecting?
Andreas