Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using Npgsql;
- namespace client
- {
- internal class Program
- {
- private static void Main(string[] args)
- {
- Console.WriteLine("Type quit to end.");
- string connection_string;
- connection_string = "Server=<servername>;Port=<port>;User Id=<userid>;Password=<pass>;Database=<db>;Pooling=false;SyncNotification=true;";
- NpgsqlConnection con = new NpgsqlConnection(connection_string);
- try
- {
- con.Open();
- NpgsqlCommand cmd = new NpgsqlCommand("listen demoapp;", con);
- cmd.ExecuteNonQuery();
- con.Notification += new NotificationEventHandler(con_Notification);
- Console.WriteLine("Subscribed to Notifications..");
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- }
- Console.WriteLine("Listening on \"demoapp\"..");
- string keyin = "";
- while (keyin.ToLower() != "quit")
- {
- keyin = Console.ReadLine();
- }
- con.Close();
- con.Dispose();
- }
- private static void con_Notification(object sender, NpgsqlNotificationEventArgs e)
- {
- Console.WriteLine("Notification received..");
- Console.WriteLine(e.Condition);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment