?
Solved

Firebird Events usage in C#

Posted on 2005-04-07
6
Medium Priority
?
5,839 Views
Last Modified: 2013-12-09
Hi,

I am new to firebird. Though I have been reading The Firebird Book and have used Firebird in studying. My question is how to create events in Firebird (1.5.2.4731) when a row is added in a table via Stored Procedure and how to register and get notified of the said event from a C# application. All this using the .Net Firebird Provider v 1.7.

The example in the book is theoretical and general. The example in this link http://firebird.sourceforge.net/index.php?op=devel&sub=netprovider&id=examples#3 is thorough but lacks helpful comments, and seems to refer to subscribing to an event on a table with an existing event created.

The example should make use of the FireBird sample database Employee.fdb so I can easily test and apply it

TIA,

PinoyBug
0
Comment
Question by:xms_dev
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
kacor earned 1000 total points
ID: 13725411
Hi PinoyBug,

I used only InterBase and Delphi so I can help in the followings to your question:

      ".. seems to refer to subscribing to an event on a table with an existing event created"

In InterBase you have to create first a trigger. InterBase has the command POST_EVENT and this informs the event handler when the event occurs (the SET TERM is needed for compatibility only):
SET TERM ^;
CREATE TRIGGER TR_NewOrder
      FOR Orders
      ACTIVE AFTER INSERT
AS
BEGIN
      POST_EVENT ’New order’;
END^
SET TERM ;^

Between the IBExpress components of Delphi there is the IBEvents component. First you register the IBEvents:
 
procedure TForm1.FormCreate(Sender: TObject);
begin
     IBDatabase1.Connected := True;
     IBTransaction1.Active := True;
     IBEvents1.Registered := True;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
     IBEvents1.Registered := False;
     IBDatabase1.Connected := False;
end;

In the Events property of the IBEvents component you write in the "new order" event. The IBEvents component has the event "OnEventAlert". To handle this event alerter you can use the following procedure for example:

procedure TForm1.IBEvents1EventAlert(Sender: TObject; EventName: String;
EventCount: Integer; var CancelAlerts: Boolean);
begin
     Application.BringToFront;
     MessageDlg('Delphi message: ' + EventName + ' event has occured.',
     mtInformation, mbOKCancel, 0);
end;

To stop the alerts you can use the CancelEvents, or restart alerting by QueueEvents method.

If a new order will be inserted you'll get the ’New order’ message.

I hope this helps

wbr kacor

0
 

Author Comment

by:xms_dev
ID: 13725577
Thanks wbr kacor. Your answer gave me an idea on implementing events based on triggers. But I am looking for implementation of events via Stored Procedure and subscription and consumption by a C# application using the FireBird .Net Provider v 1.7.

Cheers :)
0
 
LVL 10

Expert Comment

by:kacor
ID: 13751943
For event handling in IB/FB you have to use triggers undependent whether you use C# or other developping environment. As I know this is the only possibilty for this purpose. And the simplest way  you can realise this is the database side I mean. All other solution will be more complicated and not so reliable because the trigger uses the IB/FB's internal mechanism.

with best regards

kacor
0
 
LVL 19

Assisted Solution

by:Nick Upson
Nick Upson earned 1000 total points
ID: 13751979
A trigger could call a stored procedure which in turn raises the event, the application has to register interest in the event (subscription) and then consume them as they occur.

Please consider trying to describe what you wish to achieve rather than focusing on the method, we may be able to suggest something better suited.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How much do you know about the future of data centers? If you're like 50% of organizations, then it's probably not enough. Read on to get up to speed on this emerging field.
Microsoft Jet database engine errors can crop up out of nowhere to disrupt the working of the Exchange server. Decoding why a particular error occurs goes a long way in determining the right solution for it.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

593 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question