Send feedback on this topic.
Teradata.Client.Provider
RecoverConnection Event
Example 



Teradata.Client.Provider Namespace > TdConnection Class : RecoverConnection Event
The .Net Data Provider for Teradata will raise this event to add additional time for reconnection.
Syntax
'Declaration
 
Public Event RecoverConnection As EventHandler(Of TdRecoveryEventArgs)
'Usage
 
Dim instance As TdConnection
Dim handler As EventHandler(Of TdRecoveryEventArgs)
 
AddHandler instance.RecoverConnection, handler
public event EventHandler<TdRecoveryEventArgs> RecoverConnection
public:
event EventHandler<TdRecoveryEventArgs^>^ RecoverConnection
Event Data

The event handler receives an argument of type TdRecoveryEventArgs containing data related to this event. The following TdRecoveryEventArgs properties provide information specific to this event.

PropertyDescription
Application sets the timeout for recovery.  
Remarks

The Data Provider will raise this event entering reconnection and after subsequent attempts to reconnect. There is a delay period that is defined by TdConnectionStringBuilder.RecoveryStartInterval between attempts and modified by TdConnectionStringBuilder.RecoveryIntervalFactor. The event will be raised while there are active listeners.

Applications may subscribe to this event to change the initial TdConnectionStringBuilder.RecoveryTimeout value being supplied while the Data Provider is attempting to reconnect to the database. Or an application may wish to terminate an attempt at reconnection, due to an excessive long wait. By supplying a TdRecoveryEventArgs.RecoveryTimeout of 0 to the event, the reconnection attempt will be terminated.

After the first RecoveryTime is supplied, and this time expires, the next RecoveryTimeout will by default be supplied as 0, unless a listener supplies a change to this value to extend the RecoveryTimeout again.

Example
public void RecoveryEventExample (TdConnection cn)
{
    TdCommand cmd = cn.CreateCommand();
            
    cmd.CommandText = "Select col1 from TestTable"; 
            
    // register with this event
    EventHandler<TdRecoveryEventArgs> recoveryEvent =
        new EventHandler<TdRecoveryEventArgs>(OnTimeoutExpired);
        
    cn.RecoverConnection += recoveryEvent;
            
    try
    {
        // going to read through the compiler messages sent from Teradata
        using (TdDataReader dr = cmd.ExecuteReader())
        {
            String result;
            
            while (dr.Read() == true)
            {
                result = dr.GetString(0);
            
                Console.WriteLine(result);
            }
        }
    }
    finally
    {
        // need to remove delegates from the events.
        cn.RecoverConnection -= recoveryEvent;
        cn.Close;
    }
} 
             
public void OnTimeoutExpired(Object sendor, TdRecoveryEventArgs args)
{
    // assign additional time to complete reconnection
    args.RecoveryTimeout = 300;
}
Requirements

Target Platforms: Windows 8.1, Windows 10, Windows Server 2012 R2, Windows Server 2016, Windows Server 2019

See Also