dotConnect for DB2 Documentation
Devart.Data.DB2 Namespace / DB2Connection Class / ConnectionLost Event
Example

In This Topic
    ConnectionLost Event
    In This Topic
    Occurs when connection to the data source is lost in case LocalFailover is set to true. You may use this event to implicitly reconnect and reexecute the current operation.
    Syntax
    'Declaration
     
    Public Event ConnectionLost As ConnectionLostEventHandler
    public event ConnectionLostEventHandler ConnectionLost
    Event Data

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

    PropertyDescription
    The number of attempts to reconnect.  
    The reason of the connection loss.  
    The object where the connection loss occurs.  
    The state of the connection when connection is lost.  
    The application behavior when connection is lost.  
    Example
    DB2Connection conn = new DB2Connection("user id=db2admin;server=db2;database=SAMPLE;");
        conn.LocalFailover = true;
        conn.ConnectionLost += new ConnectionLostEventHandler(conn_ConnectionLost);
    
    static void conn_ConnectionLost(object sender, ConnectionLostEventArgs e) {
    
            if (e.Cause == ConnectionLostCause.Execute) {
                    if (e.Context == ConnectionLostContext.None)
                            e.RetryMode = RetryMode.Reexecute;
                    else
                            e.RetryMode = RetryMode.Raise;
            }
            else
                    e.RetryMode = RetryMode.Raise;
    }
    Dim conn As DB2Connection = New DB2Connection("user id=db2admin;server=db2;database=SAMPLE;")
    conn.LocalFailover = True
        AddHandler conn.ConnectionLost, AddressOf conn_ConnectionLost
    
    Sub conn_ConnectionLost(ByVal sender As Object, ByVal e As ConnectionLostEventArgs)
            If e.Cause = ConnectionLostCause.Execute Then
                    If e.Context = ConnectionLostContext.None Then
                            e.RetryMode = RetryMode.Reexecute
                    Else
                            e.RetryMode = RetryMode.Raise
                    End If
            Else
                    e.RetryMode = RetryMode.Raise
            End If
    End Sub
    Requirements

    Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also