dotConnect for Oracle Documentation
Devart.Data.Oracle Namespace / OracleAlerter Class
Members Example

OracleAlerter Class
Manages Oracle alerts.
Syntax
'Declaration
 
Public Class OracleAlerter 
   Inherits System.ComponentModel.Component
   Implements System.ComponentModel.IComponentSystem.IDisposable 
 
Remarks

This class is designed to subscribe to alert messages, and transfer them between client and Oracle server.

On server side, package DBMS_ALERT lets you use database triggers to alert an application when specific database values change. The alerts are transaction based and asynchronous.

On client side, use Start and Stop methods to listen to alert events, and Signal method to send message to Oracle server. You can also use the OracleAlerter.WaitAlert method to wait for single alerts.

There are two principal schemes for receiving alerts from server. First, you can use the OracleAlerter.WaitAlert method to wait for alerts during a Timeout. After an alert is received or the timeout expires the OracleAlerter does not continue to monitor the alerts. If you need to listen to the alerts continuously, use the Start method. The method monitors the alerts through cloned connection during Timeout, then pauses during Interval, then again monitors during Timeout, and so on.

This class is available only in Professional and Developer Editions. It is not available in Standard and Mobile Editions.

Example
The following sample shows how an alert can be received in the Start/Stop mode of OracleAlerter. We send an alert message by one instance of OracleAlerter and receive this message asynchronously using another OracleAlerter.
static void Main(string[] args) {
        // Open a connection to the Oracle server.       
        OracleConnection con = new OracleConnection("Server = ora; User Id = sys; Password = pwd; Mode = SysDba");
        con.Open();

        // Create the OracleAlerter instance and register it for the "my_alert" Oracle Alert.      
        OracleAlerter alerter = new OracleAlerter();
        alerter.Connection = con;
        alerter.AlertName = "my_alert";
        alerter.Timeout = 5;
        alerter.Interval = 0;

        // Set the event handler for receiving an alert.
        alerter.Alert += new OracleAlerterAlertEventHandler(Alerter_OnAlert);

        // Start the alerter. It will wait for alerts and fire the OnAlert event when any is received.
        alerter.Start();

        // Pause the thread to wait until the alerter begins listening. 
        Thread.Sleep(2000);

        // Another instance of OracleAlerter is used to generate the alert.
        // alertGenerator uses the same connection and alert name as the alerter object.
        OracleAlerter alertGenerator = new OracleAlerter();
        alertGenerator.Connection = con;
        alertGenerator.AlertName = "my_alert";

        // Send an alert to the server. At this moment alerter should raise the Alert event.
        alertGenerator.Signal("An alert message.");

        // Make a pause to wait until the alert is created and processed.
        Thread.Sleep(2000);

        // Stop listening to alerts.
        alerter.Stop();

        Console.Read();      
        con.Close();
}

    // Simple event handler for the OnAlert event.
public static void Alerter_OnAlert(object sender, OracleAlerterAlertEventArgs e) {
        Console.WriteLine("Got an alert: " + e.AlertMessage);
}
Sub Main(ByVal args As String())

        ' Open a connection to the Oracle server.
        Dim con As New OracleConnection("Server = ora; User Id = sys; Password = pwd; Mode = SysDba")
        con.Open()

        ' Create the OracleAlerter instance and register it for the "my_alert" Oracle Alert.
        Dim alerter As New OracleAlerter
        alerter.Connection = con
        alerter.AlertName = "my_alert"
        alerter.Timeout = 5
        alerter.Interval = 0

        ' Set the event handler for receiving an alert.
        AddHandler alerter.Alert, New OracleAlerterAlertEventHandler(AddressOf Alerter_OnAlert)

        ' Start the alerter. It will wait for alerts and fire the OnAlert event when any is received.
        alerter.Start()

        ' Pause the thread to wait until the alerter begins listening.
        Thread.Sleep(2000)

        ' Another instance of OracleAlerter is used to generate the alert.
        ' alertGenerator uses the same connection and alert name as the alerter object.
        Dim alertGenerator As New OracleAlerter
        alertGenerator.Connection = con
        alertGenerator.AlertName = "my_alert"

        ' Send an alert to the server. At this moment alerter should raise the Alert event.
        alertGenerator.Signal("An alert message.")

        'Make a pause to wait until the alert is created and processed.        
        Thread.Sleep(2000)

        ' Stop listening to alerts.
        alerter.Stop()

        Console.Read()
        con.Close()
End Sub

    ' Simple event handler for the OnAlert event.
Public Sub Alerter_OnAlert(ByVal sender As Object, ByVal e As OracleAlerterAlertEventArgs)
        Console.WriteLine(("Got an alert: " & e.AlertMessage))
End Sub
Inheritance Hierarchy

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         Devart.Data.Oracle.OracleAlerter

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