odp.net DB更改通知通知、odp、net、DB

2023-09-06 19:13:39 作者:酒妓

有没有办法得到一个通知,当某一个领域中的一个数据库表发生变化? 我使用的ODP.NET和Oracle 11g,在.NET 4.0应用程序。

Is there a way to get a notification when a certain field in a db table is changed ? I'm using ODP.NET and Oracle 11g, on a .NET 4.0 app.

在以后编辑: 因此,从问题的答案我明白,这将是可能的,所以我尝试过的东西。 这就是:

LATER EDIT : So, from the answers i understand that it would be possible, so i've tried something. This is how :

        OracleConnection con = new OracleConnection(constr);
        OracleCommand cmd = new OracleCommand(sql, con);
        con.Open();

        cmd.AddRowid = true;

        **OracleDependency dep = new OracleDependency(cmd);**

        cmd.Notification.IsNotifiedOnce = false;

        dep.OnChange += new OnChangeEventHandler(OnMyNotification);

        OracleDataAdapter da = new OracleDataAdapter();
        da.SelectCommand = cmd;
        da.Fill(ds, tablename);

        ultraGrid1.SetDataBinding(ds, tablename);

现在的问题是,它卡在标有类似和60秒后,它抛出一个错误:

The problem is that it gets stuck at the marked like and after 60 seconds it throws an error :

The CLR has been unable to transition from COM context 0x25f638 to COM context 0x25f7a8 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.

感谢您!

推荐答案

ODP.Net的确实现了由ADO.Net 2.0。

ODP.Net does implement the Change notification that is specified by ADO.Net 2.0.

有一个简短的描述和一个链接到一些示例code在这里:

There's a brief description and a link to some sample code here:

http://www.oracle.com/technetwork/issue-归档/ win06odp-099708.html