Thread: Using LISTEN/NOTIFY in C#.NET
CREATE OR REPLACE FUNCTION event_check() RETURNS trigger AS '
BEGIN
IF NEW.event_id = 2 THEN -- issue notification to client
NOTIFY event;
END IF;
RETURN NEW;
END;
' LANGUAGE plpgsql;
CREATE TRIGGER tr_event AFTER INSERT
ON EVENT FOR EACH ROW
EXECUTE PROCEDURE EVENT_CHECK();
CREATE OR REPLACE FUNCTION event_listener() RETURNS varchar AS '
BEGIN
LISTEN event;
RETURN null;
END;
' LANGUAGE plpgsql;
This is my C# code...
string cmdstr = "SELECT event_listener();";
OdbcCommand cmd = new OdbcCommand(cmdstr,oODBCConnection);
cmd.CommandType = CommandType.StoredProcedure;
try
{
oODBCConnection.Open();
string listening_result;
listening_result = cmd.ExecuteScalar().ToString();
rtbox_show.AppendText(listening_result.ToString() + "\r\n");
-- truncated chunks of codes --
i know that this is such a long read.. im sorry if i was such a bore but im just a student and im asking for everyone's patience..
Thanks!
Yahoo! Music Unlimited - Access over 1 million songs. Try it free.
Josephine de Castro <jedecastro23@yahoo.com> writes: > To make the long story short...my question is this..is it possible to run > the listener command in C# or will it only work in psql? There's no theoretical reason why not. You probably need to read the docs on whatever C# Postgres driver you're using (ADO, ODBC etc) and find out how it handles LISTEN/NOTIFY, as that's not (AFAIK) a standard feature. -Doug
> > To make the long story short...my question is this..is it > possible to > > run the listener command in C# or will it only work in psql? > > There's no theoretical reason why not. You probably need to > read the docs on whatever C# Postgres driver you're using > (ADO, ODBC etc) and find out how it handles LISTEN/NOTIFY, as > that's not (AFAIK) a standard feature. IIRC, you need to use the NPgsql native driver to do it. It doesn't work through ODBC or such - at least not the way you want it. //Magnus