zoukankan      html  css  js  c++  java
  • C# 监控Oracle数据变化

    用户需要授予权限 grant change notification to hfspas;
    public void GetDatabaseChange()
    {
    string sql = "select * from t_prescription_handwork where trunc(checkindate)=trunc(sysdate)";
    string constr = ConfigurationManager.ConnectionStrings["oracle"].ConnectionString;
    OracleConnection con = new OracleConnection(constr);
    con.Open();
    OracleCommand cmd = new OracleCommand(sql, con);
    OracleDependency dep = new OracleDependency(cmd);
    dep.QueryBasedNotification = false;
    //是否在Notification中包含变化数据对应的RowId
    dep.RowidInfo = OracleRowidInfo.Include;
    dep.OnChange += new OnChangeEventHandler(OnDatabaseNotification);
    //是否在一次Notification后立即移除此次注册
    cmd.Notification.IsNotifiedOnce = false;
    //此次注册的超时时间(秒),超过此时间,注册将被自动移除。0表示不超时。
    cmd.Notification.Timeout = 0;
    //False表示Notification将被存于内存中,True表示存于数据库中,选择True可以保证即便数据库重启之后,消息仍然不会丢失
    cmd.Notification.IsPersistent = true;
    cmd.ExecuteNonQuery();
    cmd.Dispose();
    con.Dispose();
    }
     
    public void OnDatabaseNotification(object src, OracleNotificationEventArgs args)
    {
    if (args.Info == OracleNotificationInfo.Insert)
    {
    DataTable changeDetails = args.Details;
    //notificationReceived = true;
    string rowid = changeDetails.Rows[0]["rowid"].ToString();
    //查找这个对象
    PrescriptionHandwork temp = PrescriptionHandwork.FetchPrescriptionHandworkByRowid(rowid);
     
    switch (args.Info)
    {
    case OracleNotificationInfo.Insert:
    UpdateAsyncGridControl(gridOrderlist, temp);
    break;
    }
    }
    }
     
     
    grant change notification to hfspas;
     
  • 相关阅读:
    k8s之Controller Manager(七)
    k8s 之apiserver部署(六)
    k8s之etcd集群安装(五)
    k8s 之harbor仓库安装(四)
    k8s 之docker环境部署 (三)
    如何在PPT中同时插入多张图片且每张占一页
    ICMPV6
    整理桌面 | Windows自带工具
    教你在Linux中如何配置网络地址
    解决在gns3中wireshark抓包无法显示和实时刷新问题
  • 原文地址:https://www.cnblogs.com/devgis/p/14180860.html
Copyright © 2011-2022 走看看