Connection recovery to db

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
bormoley
Posts: 1
Joined: Fri 11 Nov 2011 09:07

Connection recovery to db

Post by bormoley » Fri 11 Nov 2011 09:17

Hi,

Actually i would like to ask if there is any chance to recover connection to db
after connection lost for a while/server reboot?

I always get DBNETLIB err + app crash and there is no information about how to realize it on unidac.

I found example for ADO like:
while not ADOConnection.Connected and not Terminated do
begin
Sleep(TIMEOUT_CONN_RESTORE);
ADOConnection.Close;
try
ADOConnection.Open;
except
end;
end;

and confirmation that it is done in anydac component.

Whati is the situation with unidac?

Thank you.

AndreyZ

Post by AndreyZ » Fri 11 Nov 2011 10:25

Hello,

To resume lost connection, you should use the TUniConnection.OnConnectionLost event handler. The OnConnectionLost event handler is used to process fatal errors and perform failover. To make the OnConnectionLost event handler work, you should set the TUniConnection.Options.LocalFailover property to True. Note that to use the OnConnectionLost event handler, you should add the MemData unit to the USES clause of your unit. Here is an example of using the OnConnectionLost event handler:

Code: Select all

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
  UniConnection1.Options.LocalFailover := True;
  UniConnection1.Open;
end;

procedure TForm1.UniConnection1ConnectionLost(Sender: TObject;
  Component: TComponent; ConnLostCause: TConnLostCause;
  var RetryMode: TRetryMode);
begin
  RetryMode := rmReconnectExecute;
end;
In this case, if connection was lost, UniDAC will try to reconnect and reexecute the abortive operation. For more information, please read the UniDAC documentation.

Post Reply