Danh mục

Microsoft SQL Server 2005 Developer’s Guide- P9

Số trang: 20      Loại file: pdf      Dung lượng: 362.80 KB      Lượt xem: 14      Lượt tải: 0    
Hoai.2512

Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Microsoft SQL Server 2005 Developer’s Guide- P9:This book is the successor to the SQL Server 2000 Developer’s Guide, whichwas extremely successful thanks to all of the supportive SQL Server developerswho bought that edition of the book. Our first thanks go to all of the peoplewho encouraged us to write another book about Microsoft’s incredible new relationaldatabase server: SQL Server 2005.
Nội dung trích xuất từ tài liệu:
Microsoft SQL Server 2005 Developer’s Guide- P9 Chapter 5: Developing with Notification Services 159Figure 5-7 Adding a reference to the Notification Services library Next, add an import directive for the NotificationServices namespace to theDeclarations section of your project. Using the import directive enables you to usethe classes in the NotificationServices namespace without requiring you to fullyqualify the names. The import directive appears as follows:Imports Microsoft.SqlServer.NotificationServices After adding the reference to your project and its associated namespace, you cancreate the code to add a subscriber to your Notification Services application.Listing SubscriptionsTo list the subscriptions that have been created on a Notification Services instance,you can use the SubscriberEnumeration object as is shown in the following listing: Create the Instance objectDim myNSInstance As New NSInstance(NSAppInstance)Populate the list boxDim oSubscribers As SubscriberEnumeration = New _ SubscriberEnumeration(myNSInstance)ListBox1.Items.Clear() Iterate through a collection160 M i c r o s o f t S Q L S e r v e r 2 0 0 5 D e v e l o p e r ’s G u i d e For Each oSub As Subscriber In oSubscribers Add each Subscriber Name to the List ListBox1.Items.Add(oSub.SubscriberId) Next At the top of this listing you can see where the Notification Services instance called MyNSInstance is created. The important thing to notice in this line is the fact that the value “MSAppInstance” must match the value defined in your ICF file. This value can also been found by using SQL Server Management Studio to open the Notification Services node that lists the active instances. Next, a new instance of the SubscriberEnumeration object called oSubscribers is created and a For-Each loop is used to iterate through the collection of subscribers exposed by the SubscriberEnumeration object. Within the For-Each loop the name of each subscriber is added to a ListBox that can be displayed to the end user. Adding Subscriptions Of course, before you can list subscribers you must first add them. The following code sample shows how you can add a subscription using the Notification Services managed code API: Create the Instance object Dim myNSInstance As New NSInstance(NSAppInstance) Create the Application object Dim myNSApp As New NSApplication(myNSInstance, NSApp) Create the Subscriber Dim oSubscriber As New Subscriber(myNSInstance) oSubscriber.SubscriberId = TextSub.Text oSubscriber.Add() Add a device for the subscriber DeviceName must match subscription Dim oDevice As New SubscriberDevice(myNSInstance) oDevice.DeviceName = myDevice oDevice.SubscriberId = TextSub.Text oDevice.DeviceTypeName = File oDevice.DeviceAddress = TextSub.Text & @teca.com oDevice.DeliveryChannelName = FileChannel oDevice.Add() Create the subscription Dim oSubscription As New Subscription(myNSApp, ShipStore) oSubscription(DeviceName) = myDevice Chapter 5: Developing with Notification Services 161oSubscription(SubscriberLocale) = en-USoSubscription.SubscriberId = TextSub.Text Hard code the store ID for the exampleoSubscription(StoreID) = 1Dim sSubId As String = oSubscription.Add()oSubscription.Add()Display the new Subscriber IDListBox1.Items.Add(TextSub.Text)TextSub.Text = First a Notification Services instance object named myNSInstance is created,followed by an Application object named myNSApp. These must correspond to thedefinitions that were previously defined in the XML-based Notification Servicesconfiguration file. For this example, the NSInstance object must be created using thevalue of “NSAppInstance,” which must match the name of the Notifications ServicesInstance as defined in the element of the ICF file. Likewise, theApplication object, NSApplication, must use the value of “NSApp” to match the valueused in the element of the ICF file. You can also see these valuesbeneath the Notification Services node in the SQL Server Management Studio. Next, a Subscriber must be created and notification delivery devices must beadded to the subscriber. A new subscriber is created by passing the NotificationServices Instance name to the Subscriber object’s constructor. Once the Subscriberobject has been instantiated, the SubscriberID property is set with a string value thatidentifies the subscriber. Here that value comes from a Textbox named TextSub.Then the Add method is called to create the subscriber. As you might expect, theDelete and Update methods must be used if you subsequently want to modify ordelete the subscriber information. NOTE Adding a subscriber updates the NSDataSubSubscriptions table along with a couple of other tables in the NSAppInstanceNSApp database. However, you should not directly update these tables. Instead, you should only add, update, and delete subscribers using the NotificationServices API or the stored procedure generated with the Notification Services application. Once the subscriber has been added, at least one device must be added to thesubscriber using the SubscriberDevice object. The SubscriberId in combination withthe DeviceName property uniquely identifies the device in the system. The value usedfor the DeliveryChannel property specifies the method by which the notification will162 M i c r o s o f t S Q L S e r v e r 2 0 0 5 D e v e l o p e r ’s G u i d e be generated. In this example, the notification will be created in the file system. The actual output file was defined in ...

Tài liệu được xem nhiều: