TUniConnection and Connection link failure
TUniConnection and Connection link failure
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!
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
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: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.
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;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
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
Please inform us of the "Communication link failure" error number. For this, you can use the following code:Note that to run this code, you should add the OLEDBAccessUni unit to the USES clause of your unit.
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;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:
Two situations:
1. If i click the button after switch off WIFI:
The message is:
Here is 'Communication link failure'
The message is:
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()1. If i click the button after switch off WIFI:
The message is:
2. If i use TTimer with default interval 1000 and switch off WIFI:ErrorCode: -2147467259; OLEDBErrorCode-2147467259
ErrorCode: 121
Code: Select all
procedure TMainForm.OnTimer1(Sender: TObject);
begin
BitBtn.Click;
end;
The message is:
ErrorCode: -2147467259; OLEDBErrorCode-2147467259
-
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;-
AndreyZ