1。修改kbmMWUnidac单元的TkbmMWUNIDACConnection.InternalOpenConnection方法,加上:
//支持unidac重联
FDatabase.Options.LocalFailover:=Options.LocalFailover;
FDatabase.OnConnectionLost:=OnConnectionLost;
FDatabase.AfterConnect:=AfterConnect;
2.处理UniConnection组件:
设置Options.LocalFailover:=True;
编码OnConnectionLost及AfterConnect事件:
procedure TFServerDM.UniMysqlConnectionConnectionLost(Sender:
TObject;
Component: TComponent; ConnLostCause:
TConnLostCause;
var RetryMode: TRetryMode);
begin
if (Sender as TUniConnection).Tag < 1
then
begin
RetryMode :=
rmReconnectExecute;
(Sender as
TUniConnection).Tag := (Sender as TUniConnection).Tag + 1;
end
else
begin
RetryMode :=
rmRaise;
(Sender as
TUniConnection).Tag := 0;
end;
end;
procedure TFServerDM.UniMysqlConnectionAfterConnect(Sender: TObject);
begin
(sender as TUniConnection).Tag := 0;
end;
感谢清幽傲竹!用这方法,就不怕数据库与AppServer的异常断开了!
我没有遇到这个问题,可能的原因是生产环境好,用的还是MSSQL,联接没有异常断开过,竹子用的是MYSQL。