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 when starting reconnection and after subsequent attempts to reconnect. There is a delay period between reconnection attempts that is defined by TdConnectionStringBuilder.RecoveryStartInterval 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. Applications may terminate reconnection attempt due to an excessive long wait by supplying a TdRecoveryEventArgs.RecoveryTimeout of 0 to the event.

After the first RecoveryTime is supplied and that time expires, the next RecoveryTimeout will be supplied as 0 by default 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 an event handler for this event
    EventHandler<TdRecoveryEventArgs> recoveryEvent =
        new EventHandler<TdRecoveryEventArgs>(OnTimeoutExpired);
        
    cn.RecoverConnection += recoveryEvent;
            
    try
    {
        // read the results
        using (TdDataReader dr = cmd.ExecuteReader())
        {
            String result;
            while (dr.Read() == true)
            {
                result = dr.GetString(0);
                Console.WriteLine(result);
            }
        }
    }
    finally
    {
        // unregister the event handler
        cn.RecoverConnection -= recoveryEvent;
        cn.Close();
    }
} 
             
public void OnTimeoutExpired(Object sender, TdRecoveryEventArgs args)
{
    // assign additional time to complete reconnection
    args.RecoveryTimeout = 300;
}
Requirements
ProductVersionsPlatforms
.NET6, 7Windows, Linux, MacOS
.NET Framework4.6.2, 4.7, 4.7.1, 4.7.2, 4.8Windows
.NET Standard2.0Windows, Linux, MacOS
See Also