我在使用OracleDependency时遇到了一些问题。
我已经阅读了msdn和oracle上的文档,并复制了一些代码来尝试它。
但是这不起作用,插入完成时on_my_event事件不会触发。
有谁知道为什么?
我的用户对数据库具有CHANGE NOTIFICATION权限。 Oracle Server是11.2.0.3.0。
以下是代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Oracle.DataAccess.Client;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
string connection_string = "Data Source=My_srv;User Id=My_usr;Password=My_pwd;";
OracleConnection connection = null;
OracleDependency dependency = null;
OracleCommand my_select = null;
OracleCommand my_insert = null;
public Form1()
{
InitializeComponent();
}
private void TB_insert_event(object sender, EventArgs e)
{
if (TB_insert.Text == "Name of your insert")
TB_insert.Clear();
}
private void insert(object sender, EventArgs e)
{
connection = new OracleConnection(connection_string);
my_insert = connection.CreateCommand();
my_insert.CommandText = "INSERT INTO USR_DEV_TRUNK.WPARAM (wpa_codeparam) VALUES ('" + TB_insert.Text + "')";
connection.Open();
my_insert.ExecuteNonQuery();
connection.Close();
}
private void Set_dep(object sender, EventArgs e)
{
OracleDependency.Port = 3048;
connection = new OracleConnection(connection_string);
connection.Open();
my_select = connection.CreateCommand();
my_select.CommandText = "SELECT wpa_codeparam FROM USR_DEV_TRUNK.WPARAM";
dependency = new OracleDependency();
dependency.AddCommandDependency(my_select);
my_select.Notification.IsNotifiedOnce = false;
my_select.ExecuteNonQuery();
dependency.OnChange += new OnChangeEventHandler(on_my_event);
TB_dependency.Text = "The dependency is set, do your insert to see if it works";
connection.Close();
}
public void on_my_event(object obj, OracleNotificationEventArgs arg)
{
TB_dependency.Text = "Yay ! It worked !";
}
}
}
我有两个按钮:
设置我的依赖关系(功能(点击):Set_dep)
我要插入一个(功能(点击):插入)
我有两个文本框:
获取插件(名称:TB_insert)
显示依赖状态(名称:TB_dependency)
答案 0 :(得分:0)
您确定端口3048上的数据包没有被防火墙阻止吗?
此外,一旦设置了依赖关系,您是否可以通过查询USER_CHANGE_NOTIFICATION_REGS / DBA_CHANGE_NOTIFICATION_REGS视图来查看它?