LadislavM LadislavM - 22 days ago 6
C# Question

Change Notification with Oracle Dependency in C#

I'm trying to get oracle database change notification in c#. I found
this tutorial about how to get these notifications. I've also created simple win form application for catching notifications

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
SetUpNotification();
}

private void SetUpNotification()
{
var login = "DATA SOURCE=XE;PERSIST SECURITY INFO=True;USER ID=USR;PASSWORD=PWD";

OracleConnection conn = null;
OracleDependency dep = null;

try
{
conn = new OracleConnection(login);

var cmd = new OracleCommand("select * from customer_details", conn);

conn.Open();

cmd.AddRowid = true;
dep = new OracleDependency(cmd);
cmd.Notification.IsNotifiedOnce = false;

dep.OnChange += new OnChangeEventHandler(dep_OnChange);
}
catch(Exception e)
{
MessageBox.Show(e.Message, e.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

void dep_OnChange(object sender, OracleNotificationEventArgs eventArgs)
{
MessageBox.Show(eventArgs.Details.ToString(), "Database changed");
}
}


Login string and OracleCommand cmd are 100% fine. I tried also to change database programmatically, it changed data in database, but didn't fired OnChange event.

I also granted notifications tu USR user

grant change notification to USR


and job_queue_processes are greater than zero.

Can be a problem in a fact, that I am using Express edition of oracle database?

Answer

I found out the solution. Problem wasn't in edition of Oracle database, but in the version. Version of Oracle server was 11.2.0.2.0 and version of client was 11.2.0.3.0 and this little difference was causing the problem.

So for the future, alway check the versions of client and server, when encountering similar problem.