TUniConnection and Connection link failure

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Dido
Posts: 20
Joined: Fri 18 Sep 2009 20:04

TUniConnection and Connection link failure

Post by Dido » Sat 11 Feb 2012 12:44

My application read data from server periodically with TTimer.
I use UniConnection.Connected property to check the connection
and if is True do execute the query. All worked fine, but when
error 'Connection link failure.' is raise, Connected property is
still True and i execute query with error.
How do i check when is possibe /connection is OK/
to execute Queries?
Thanks!

AndreyZ

Post by AndreyZ » Mon 13 Feb 2012 10:43

Hello,

The only way to check if a connection is valid, is to perform any operation through it. 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.

Dido
Posts: 20
Joined: Fri 18 Sep 2009 20:04

Post by Dido » Wed 15 Feb 2012 10:25

Yes, all work fine with failover, but the problem is
OnConnectionLost is not firing in same cases.
If use a laptop with WIFI connection and turn off
WIFI with EXTERNAL HARDWARE button then
open query - OnConnectionLost is not firing and
raise error message 'Communication link failure'

Same problem is described in these topics:

http://www.devart.com/forums/viewtopic.php?t=22418
http://www.devart.com/forums/viewtopic.php?t=17637

AndreyZ

Post by AndreyZ » Wed 15 Feb 2012 12:52

Please inform us of the "Communication link failure" error number. For this, you can use the following code:

Code: Select all

procedure TMainForm.BitBtnClick(Sender: TObject);
var
  i: integer;
  er: EMSError;
  ts: string;
begin
  try
    // code that causes the "Communication link failure" error    
  except
    on E: EUniError do begin
      er := EMSError(E.InnerError);
      ts := '';
      for i := 0 to er.ErrorCount - 1 do
        ts := ts + 'ErrorCode: ' + IntToStr(er.Errors[i].ErrorCode) + '; OLEDBErrorCode' + IntToStr(er.Errors[i].OLEDBErrorCode) + #13#10;
      ShowMessage(ts);
    end;
  end;
end;
Note that to run this code, you should add the OLEDBAccessUni unit to the USES clause of your unit.

Dido
Posts: 20
Joined: Fri 18 Sep 2009 20:04

Post by Dido » Wed 15 Feb 2012 13:08

Hello,
thank for your reply!
Now i can't run your code, maybe tomorrow,
but UniConnectionOnError event returned
Message: 'Communication link failure.'
Error code: -2147..................... many (9-12) digits.
(i don't remember it exactly, maybe was integer -2147483648)

AndreyZ

Post by AndreyZ » Wed 15 Feb 2012 14:47

Please execute the above code and provide us the exact error number.

Dido
Posts: 20
Joined: Fri 18 Sep 2009 20:04

Post by Dido » Thu 16 Feb 2012 09:48

Hello,
i executed your code on machine with
Native Client SQL Server 2008 R2 SP1 and Windows 7 x86 HomePremium SP1

I use for SQL statement:

Code: Select all

select GETDATE()
Two situations:
1. If i click the button after switch off WIFI:
The message is:
ErrorCode: -2147467259; OLEDBErrorCode-2147467259
ErrorCode: 121
2. If i use TTimer with default interval 1000 and switch off WIFI:

Code: Select all

procedure TMainForm.OnTimer1(Sender: TObject);
begin
  BitBtn.Click;  
end;
Here is 'Communication link failure'

The message is:
ErrorCode: -2147467259; OLEDBErrorCode-2147467259

AndreyZ

Post by AndreyZ » Thu 16 Feb 2012 14:18

It occured that this information is not enough. Please execute the following code and inform us of the ts variable value:

Code: Select all

try
  // code that causes the "Communication link failure" error
except
  on E: EUniError do begin
    er := EMSError(E.InnerError);
    ts := 'ErrorCode: ' + IntToStr(er.ErrorCode) + '; OLEDBErrorCode' + IntToStr(er.OLEDBErrorCode) + '; ' +
          'SeverityClass: ' + IntToStr(er.SeverityClass) + '; State' + IntToStr(er.State) + '; ' +
          'MSSQLErrorCode: ' + IntToStr(er.MSSQLErrorCode);
    ShowMessage(ts);
  end;
end;

Dido
Posts: 20
Joined: Fri 18 Sep 2009 20:04

Post by Dido » Fri 17 Feb 2012 10:51

With your last code the error message is:
ErrorCode: -2147467259; OLEDBErrorCode-2147467259;
SeverityClass: 4; State176; MSSQLErrorCode: 0

AndreyZ

Post by AndreyZ » Fri 02 Mar 2012 14:43

We cannot reproduce this problem using the cable network. For the time being we don't have the possibility to check this problem using WI-FI connection. If you can reproduce this problem using the cable network, please describe the way of doing it and we will investigate this question.

Post Reply