使用 C# 中的 Oracle 依赖项更改通知 [英] Change Notification with Oracle Dependency in C#

查看:40
本文介绍了使用 C# 中的 Oracle 依赖项更改通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 c# 中获取 oracle 数据库更改通知.我发现本教程关于如何获取这些通知.我还创建了简单的 win 表单应用程序来捕捉通知

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");
    }
}

登录字符串和 OracleCommand cmd 100% 没问题.我还尝试以编程方式更改数据库,它更改了数据库中的数据,但没有触发 OnChange 事件.

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.

我也向 USR 用户授予了通知

I also granted notifications tu USR user

grant change notification to USR

和 job_queue_processes 大于零.

and job_queue_processes are greater than zero.

事实上,我使用的是oracle数据库的Express版,这可能是个问题吗?

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

推荐答案

我找到了解决方案.问题不在于Oracle 数据库的版本,而在于版本.Oracle 服务器的版本是 11.2.0.2.0,客户端的版本是 11.2.0.3.0,这个微小的差异导致了问题.

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.

这篇关于使用 C# 中的 Oracle 依赖项更改通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆