Force reconnect code if connection lost

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Magnus van Aardt
Posts: 3
Joined: Tue 13 Apr 2010 06:26

Force reconnect code if connection lost

Post by Magnus van Aardt » Wed 14 Apr 2010 07:11

Just want to find out if it is possible to force the execution of the reconnect code if the msconnection comp lost the connection. This is when a automatic failover occurs. Normally it works fine and the onconnectionlost event is fired, but sometimes a error occurs, example network cable is unplugged,and the onerror event is fired. i want to know if it is possible to try re-establish the connection, from within the onerror event, using the same code that is used when the failover occurs succesfully and the onconnectionlost event is fired.

The reason is that is seems that if connection is redirected successfully all transactions are restored for the connection. If I just close and reopen the connection in the onError event, all the transactions are lost.
I just want to re try the entire reconnect process, after some additional check to ensure that failover is complete and the new principal is ready.


Devart Team
Posts: 2885
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Wed 14 Apr 2010 09:47

When LocalFailover is used and transaction started, on connection lost the OnError event is arised instead of OnConnectionLost because SQL Server doesn't support restoring transaction after disconnect. SQL Server automatically rolls back a transaction when connection lost occurs.

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

Re: Force reconnect code if connection lost

Post by Dido » Fri 20 Feb 2015 08:23

I have similar problem:
I use UniDAC with SQL Server, LocalFailover is used and OnConnectionLost is arised when
connection is lost. All is OK.
But when the computer go to in sleep mode and then is turned on,
connection is lost but OnConnectionLost is NOT arired. Instead OnConnectionLost,
OnError is arised with ErrorCode=10053. I use prNativeClient.
How can mannualy arise OnConnectionLost event from OnError event?

Devart Team
Posts: 1001
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Force reconnect code if connection lost

Post by azyk » Mon 23 Feb 2015 12:32

You can't initialize the OnConnectionLost event by yourself. If a critical error occurred when working with the connection, then the OnError event will occur - and all the other operations will be handled according to this event.

Post Reply