Guest User

Untitled

a guest
Jun 25th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3. using Oracle.DataAccess.Client;
  4.  
  5. namespace OracleNotification
  6. {
  7. class Program
  8. {
  9. private static OracleDependency _dep;
  10. private const string ConnString = "DATA SOURCE=ORCL; User Id=USERNAME; Password=PASS;";
  11.  
  12. static void Main(string[] args)
  13. {
  14. SetUpNotification();
  15. Console.ReadLine();
  16. DeRegisterNotification();
  17. }
  18.  
  19. private static void SetUpNotification()
  20. {
  21. try
  22. {
  23. using (var conn = new OracleConnection(ConnString))
  24. {
  25. var cmd = new OracleCommand("Select * from exchnge.JMORA_TEST3", conn);
  26. conn.Open();
  27. cmd.AddRowid = true;
  28. _dep = new OracleDependency(cmd, false, 0, true);
  29.  
  30. _dep.OnChange += dep_OnChanges;
  31. cmd.ExecuteNonQuery();
  32. conn.Close();
  33. }
  34. }
  35. catch (Exception e)
  36. {
  37. Debug.WriteLine(e.Message);
  38. }
  39. }
  40.  
  41. private static void dep_OnChanges(object sender, OracleNotificationEventArgs eventArgs)
  42. {
  43. var data = eventArgs.Details.DefaultView.Table.Rows[0][2].ToString();
  44. Debug.WriteLine(data);
  45. }
  46.  
  47. private static void DeRegisterNotification()
  48. {
  49. using (var conn = new OracleConnection(ConnString))
  50. {
  51. conn.Open();
  52. _dep.RemoveRegistration(conn);
  53. conn.Close();
  54. }
  55. }
  56. }
  57. }
Add Comment
Please, Sign In to add comment