StateChange event

Occurs when this connection changes state.

Syntax
Visual Basic
Public Overrides Event StateChange As StateChangeEventHandler
C#
public event override StateChangeEventHandler StateChange;
Remarks

To process state change messages, you must create a System.Data.StateChangeEventHandler delegate and attach it to this event.

Example

The following code defines a state change event handler.

' Visual Basic
Private Sub MyStateHandler( _
      obj As Object, args As StateChangeEventArgs _
    )
  System.Console.WriteLine( _
      "StateHandler: " + args.OriginalState + " to " _
      + args.CurrentState _
    )
End Sub

// C#
private void MyStateHandler(
      object obj, StateChangeEventArgs args
    )
{
  System.Console.WriteLine(
      "StateHandler: " + args.OriginalState + " to "
      + args.CurrentState
    );
}

The following code adds the MyStateHandler to the connection named conn.

' Visual Basic
AddHandler conn.StateChange, AddressOf MyStateHandler

// C#
conn.StateChange += new StateChangeEventHandler(MyStateHandler);
Event data
  • CurrentState   Gets the new state of the connection. The connection object will be in the new state already when the event is fired.

  • OriginalState   Gets the original state of the connection.

See also