|
本帖最后由 e54f 于 2019-7-11 17:32 编辑
To avoid infinite attempts of reconnecting to the server, you can use a counter variable. For example, you can use the following code:
- var
- RetryCount: Integer;
- procedure TMainForm.MyConnection1ConnectionLost(Sender: TObject;
- Component: TComponent; ConnLostCause: TConnLostCause;
- var RetryMode: TRetryMode);
- begin
- if RetryCount < 2 then begin
- Inc(RetryCount);
- RetryMode := rmReconnectExecute;
- end
- else begin
- RetryCount := 0;
- RetryMode := rmRaise;
- end;
- end;
复制代码
In this case, MyDAC will try to reconnect to the server twice, and in case of failure will generate an exception.
rmRaise An exception is raised.
rmReconnect Reconnect is performed and then exception is raised.
rmReconnectExecute Reconnect is performed and abortive operation is reexecuted. Exception is not raised.
|
|