深圳全飞鸿

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1022|回复: 0
打印 上一主题 下一主题

MyDac数据库重连探讨

[复制链接]

16

主题

32

帖子

194

积分

注册会员

Rank: 2

积分
194
跳转到指定楼层
楼主
发表于 2019-7-11 17:23:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 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.

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|nagomes  

GMT+8, 2025-5-5 06:21 , Processed in 0.024519 second(s), 21 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表