Sunday, October 18, 2009

Database Change Notification in Oracle

The SQL Server driver for ADO.NET has the SqlDependency class. It enables applications to receive notifications when there is a change in a query result set, schema objects, or the state of the database. Using SqlDependency, an application can maintain the validity of the client-side cache easily. At one of my clients we aren't using SQL Server but Oracle. As I searched throught the standard ADO.NET driver for Oracle (System.Data.Oracle) I couldn't find a similar class.

After some digging on the Oracle site I found that Oracle has a separate driver for .NET next to the standard ADO.NET driver. If you download the Oracle Data Provider for .NET (Oracle.DataAccess) you'll find the OracleDependency class that has the same functionality as the SqlDependency class.

A simple example to show this functionality:

1: publicclass Notification

2: {

3: publicstaticbool IsNotified = false;

4:

5: publicstaticvoid Main(string[] args)

6: {

7: //To Run this sample, make sure that the connecting user hase change notification privilege

As every change notification registration consumes database memory, storage or network resources, or some combination thereof, it's important to be carefull when using this feature. In order to scale well with a large number of mid-tier clients, use it only for a few tables that change infrequently.

1 comment:

Anonymous
said...

Hi Mr. Wullems,

Thank you for this excellent material.

I've implemented the same for Oracle where I've registered multiple tables. When any of table data has changed, I get the notification and from "args.Source" in "OnMyNotificaton" method I get the table name which got changed.But I could not find any way to know which table has changed in SqlDependency.