tags:

views:

34

answers:

2

Scenario: An application is started, it connects to the DB and registers itself to listen for a specific event name. Then using either a trigger or stored procedure when certain criteria are met the event may be raised. The DB then notifies all the applications that have registered that they are listening for that event. The application is then able to act and go and do some processing. This saves the program from having to constantly poll the database to see if the criteria has been met.

This scenario is possible with Interbase / FirebirdSQL but is it possible to do with SQL Server (2005 or higher) and if so what should I be looking for as I am strugling to find any information on this sort of thing. If it is not possible then is there a better way to handle this scenario to not have to poll.

A: 

A potential solution for this could be CLR triggers, with a data driven subscription service.

When the required update happens, the trigger catches it then looks up in the database what the applications waiting for that event are, then they are called through some common means (webservice etc.) to a standard interface.

ck
+2  A: 

Yes. You can use Service Broker notifications for this.

Though I guess the caveat in this article about not having too many clients registered will still apply. How many clients might you have awaiting notifications?

Martin Smith
From the looks of it, Service Broker would allow messages to be passed through to different database instances. Is it possible for an application to register itself as a receiver?
Lieven
@Lieven - Yes. I haven't done it myself but that is how the SQLCacheDependency works in .NET.
Martin Smith
@Martin: you are right. From here <http://blogs.digitaldeposit.net/saravana/post/2005/09/26/SQL-Service-Broker-Management-Studio-2005.aspx>, it looks like it's possible. *By default, an instance of SQL Server does not contain a Service Broker endpoint. Thus, Service Broker does not send or receive messages over the network by default. You must create a Service Broker endpoint to send or receive messages outside the SQL Server instance.*
Lieven