Hi,
with the following code, I try to use the Oracle change notification:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Devart.Data.Oracle;
using System.Data;
namespace DBEventBroker
{
class Eventbroker
{
public void TestOracleChangeNotification()
{
OracleCommand cmd;
OracleDependency dep;
DataSet ds = new DataSet();
string tablename = "table";
string sqlSelect = "select EventId, Event, TestCol FROM E$Test where EventID = 1 ";
OracleConnection con = new OracleConnection("User Id=TestUser;Password=password;Data Source=localDB");
cmd = new OracleCommand(sqlSelect);
OracleDependency.Port = 1521;
dep = new OracleDependency(cmd);
cmd.Notification.IsNotifiedOnce = false;
cmd.Notification.RowLevelDetails = true;
cmd.Notification.Timeout = 0;
dep.OnChange += new OnChangeEventHandler(OnMyNotificaton);
OracleDataAdapter da = new OracleDataAdapter(cmd);
da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
try
{
da.Fill(ds, tablename);
}
catch (Exception ex)
{
string message = ex.Message;
}
}
public static void OnMyNotificaton(object src, OracleNotificationEventArgs args)
{
//args.Details is always NULL
if ( args.Details != null && args.Details.Rows.Count > 0)
{
string type = Enum.GetName(typeof(OracleNotificationInfo), args.Details.Rows[0].ItemArray[1]);
if (type == OracleNotificationInfo.Delete.ToString())
return;
}
else
return;
DataRow Row = args.Details.Rows[0];
DataRowCollection detailRows = args.Details.Rows;
}
}
}
If I made an Insert to E$Test, the Oracle database fires an event, which is caught by the method OnMyNotificaton.
But the DataTable Details in OracleNotificationEventArgs is always null (see comment above).
Are there any settings in Oracle database which I have to change or is something wrong in my C# code?
It would be nice if you could help me.
Oracle change notification doesnt work.
This is a settings issue. Please turn off the query based notification:
-->
Code: Select all
dep = new OracleDependency(cmd);
Code: Select all
dep = new OracleDependency(cmd);
dep.QueryBasedNotification = false;