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;
专业从事基于C#,WinForm ,WPF,Silverlight,WCF以及MS Sql Server 2000/2005/2008/2012 Oracle 9i/10g/11g数据库系统的ERP,CRM,企业进销存等各种数据库管理系统开发。Asp.net,Asp.net mvc,Webservice,WCF, Webapi等服务程序开发。
基于Oracle MySQL MSSql postgresql各种数据库的管理系统数据同步服务。以及基于MapXtreme, Arcgis Engine ,以及基于Arcgis for silverlight/Javascript的WebGIS等相关的GIS系统二次开发。基于Windows 10 Mobile的移动端开发方案。针对各种系统的二次开发维护,并提供相关开发的技术性支持,如程序BUG解决,应用系统架构,技术难题攻克等相关技术服务。
联系方式: QQ :80163278(devgis) 邮箱:devgis@qq.com
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步