Page 1 of 1

TUniConnection and Connection link failure

Posted: Sat 11 Feb 2012 12:44
by Dido
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!

Posted: Mon 13 Feb 2012 10:43
by AndreyZ
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.

Posted: Wed 15 Feb 2012 10:25
by Dido
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

Posted: Wed 15 Feb 2012 12:52
by AndreyZ
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.

Posted: Wed 15 Feb 2012 13:08
by Dido
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)

Posted: Wed 15 Feb 2012 14:47
by AndreyZ
Please execute the above code and provide us the exact error number.

Posted: Thu 16 Feb 2012 09:48
by Dido
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

Posted: Thu 16 Feb 2012 14:18
by AndreyZ
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;

Posted: Fri 17 Feb 2012 10:51
by Dido
With your last code the error message is:
ErrorCode: -2147467259; OLEDBErrorCode-2147467259;
SeverityClass: 4; State176; MSSQLErrorCode: 0

Posted: Fri 02 Mar 2012 14:43
by AndreyZ
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.