深圳全飞鸿

标题: MyDac数据库重连探讨 [打印本页]

作者: e54f    时间: 2019-7-11 17:23
标题: MyDac数据库重连探讨
本帖最后由 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:

  1. var
  2.   RetryCount: Integer;

  3. procedure TMainForm.MyConnection1ConnectionLost(Sender: TObject;
  4.   Component: TComponent; ConnLostCause: TConnLostCause;
  5.   var RetryMode: TRetryMode);
  6. begin
  7.   if RetryCount < 2 then begin
  8.     Inc(RetryCount);
  9.     RetryMode := rmReconnectExecute;
  10.   end
  11.   else begin
  12.     RetryCount := 0;
  13.     RetryMode := rmRaise;
  14.   end;
  15. 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.






欢迎光临 深圳全飞鸿 (http://www.nagomes.com/disc/) Powered by Discuz! X3.2