Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Get Started Using SQL Server 2005 Notification Services : Page 4

Because of the complex configuration options required to write SQL Server 2005 Notification Services (SQLNS) applications, it can be difficult to get started, but after you've learned the concepts and ideas behind SQLNS, you'll find yourself able to write great applications that are both scalable and extensible using common interfaces.


advertisement
Defining Subscriptions
To send out notifications SQLNS must know:
  • Who should receive notifications
  • What information to send
  • The target device to which the notification should be sent
You set up this information using the Subscription Management Objects from a .NET application. The Subscription Management Objects are a set of .NET classes implemented in an assembly shipped with SQLNS. SQLNS stores subscription information in the instance database (not in the application database). This design decision makes it possible to use subscriber information in more than one SQLNS application.

Before you can manage subscriptions you must define a Subscription class in the Application Definition file. You also need to configure a Delivery Channel in the Instance Configuration file. The Subscription class stores information about the event, the target device, and the language in which the notification should be delivered. Listing 3 shows the Subscription class for the sample application. Using this Subscription class, nscontrol.exe will create a new table when you use it to update the SQLNS instance. The column DeviceName stores the name of the device to which the SQLNS will publish the subscription. The column SubLocale defines the language in which SQLNS sends the notification. Using the StockCode, ExchangeCode, and TriggerVal columns, users can decide which stocks they want to be notified about when a change occurs. For example, a typical notification request might be: "I want to be informed about the stock MSFT (column StockCode) that trades at NYSE (column ExchangeCode) whenever as the stock price exceeds $7.00 (column TriggerVal)."

A Subscription Management application must be able to perform these three tasks:

  • Create a new subscriber
  • Specify the target device for the new subscriber
  • Create a subscription for the new subscriber
To communicate with an existing SQLNS instance you need a reference to it. The sample application accomplishes this using the NSInstance object. This object's constructor receives a parameter containing the instance name of the SQLNS instance to manage. The SubscriberDevice class represents the subscriber's target device, and the Subscription class represents a subscription. With all this information in hand, it's very easy to manage all three tasks. Listing 4 shows the required code in C#. You can use this same code in either an ASP.NET or Windows Forms application.


The most interesting method is AddSubscription. That method creates a new Subscription instance, then uses its SetFieldValue method to set the various properties of the Subscription. SQLNS uses this information to generate notifications from newly received events.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap