This sample shows how to receive query notifications using notification services in SQL Server 2005. To do this, the following things are required:- SQL Server 2005
- Notification services must be installed. You will see this as a folder within SQL Server Management Studio (Notification Services)
- Broker Service must be enabled for the database. If you are using the DDT, just check this in the Database properties. Otherwise, you can enable this like this:
ALTER DATABASE StrataFrameSample SET ENABLE_BROKER
In this example, you will need to manually execute the above command to turn on the broker service for the StrataFrameSample database (not by default). - Set the ReceiveQueryNotificationServices property to True on the BO
Next, you will want to handle the ServerDataChanged event. This will be raised if there is an error qith the notification or if the query has changed. If there was an error with the subscription, the Info property will indicate Invalid (in most cases). If the ServerDataChanged event is not raised immediately after query is called, then it is subscribed. You can determine this for sure by looking at the queues in SQL Server Management Studio.
Also, when creating queries, wildcards will not work and the schema names must be included in the queries.
Won't Work
SELECT * FROM Customers
Will Work
SELECT cust_LastName FROM dbo.Customers
How To Use This Sample
Simply run two instances of this sample once compiled. Change the value of the last or first name on one of the forms. You will then see a message box appear with the notification values and then refresh the dialog with the changes.