Você está na página 1de 36

Notification Services Tutorial The Notification Services tutorial teaches you how to build a simple Notification Services application.

The tutorial uses a SQL Server Management Studio solution to make it easy to edit tutorial files and then build the solution using SQL Server Management Studio Object Explorer. What You Will Learn In this tutorial, you will build a weather notification application. This application will let users subscribe to and receive weather notifications for individual cities. You will start with a minimal application definition file (ADF) and use a predefined instance configuration file (ICF) to create an instance of Notification Services that hosts the weather application. The information in the ICF and ADF is compiled and then used to create an instance database and an application database. The databases are used to store data and run the application. You will then update the ADF to describe the weather event, notification, and subscription data, and configure application execution settings. Every time that you update the application, you apply the changes to the application database. In the last two lessons of this tutorial, you will add subscriber and subscription data, and then add event data and view the resulting notifications. This is a simple application that does not use some of the more advanced features of Notification Services, such as digest or multicast delivery, custom event providers, custom content formatters, and custom delivery protocols. However, this tutorial does show the core steps for building a notification application that uses Notification Services. Requirements Before you start the tutorial, you should be familiar with Notification Services concepts and terminology. To learn about Notification Services, see Introducing SQL Server Notification Services. This tutorial is intended to be used on a single computer that has all the required software installed. Make sure that you have done the following:

You have installed the Database Engine, Notification Services, and Workstation Components. For more information, see Installing SQL Server 2005. You have installed the Notification Services samples. For more information, see Installing Samples. You have started an instance of the Database Engine. For more information, see Starting and Restarting Services.

Note: Before reviewing tutorials, you should add Next and Previous buttons to the document viewer toolbar. For more information, see Adding Next and Previous Buttons to Help. Contents This tutorial is divided into 11 lessons. You must complete all tutorial lessons in order to develop a working Notification Services application. Lesson 1: Opening and Examining the Tutorial Solution In this lesson, you open the SQL Server Management Studio solution and examine the files in the solution. Lesson 2: Performing an Initial Build of the Tutorial Instance In this lesson, you review the application definition file (ADF) for the Weather application and the instance configuration file (ICF) for the Tutorial instance of Notification Services, and then perform an initial build of the instance and application. Lesson 3: Adding an Event Class In this lesson, you add an event class to the ADF that describes event data. Lesson 4: Adding a Notification Class In this lesson, you add a notification class to the ADF that describes notification data, formatting, and delivery. Lesson 5: Adding a Subscription Class In this lesson, you add a subscription class to the ADF that describes subscription data and the rules that generate notifications. Lesson 6: Adding an Event Provider In this lesson, you add a non-hosted event provider declaration to the ADF. This is used to identify events added using the event submission stored procedures. Lesson 7: Configuring the Generator and Distributor In this lesson, you specify where the application's generator and distributor run, and the polling interval for the distributor. Lesson 8: Altering Application Execution Settings

In this lesson, you specify generator, distributor logging, and data removal settings. Lesson 9: Registering, Enabling, and Starting the Instance In this lesson, you register, enable, and start the instance of Notification Services. Lesson 10: Adding Subscribers and Subscriptions In this lesson, you add subscribers to the instance database and subscriptions to the application database. Lesson 11: Submitting Events to the Weather Application In this lesson, you add events to the application and then view the resulting notifications. Lesson 1: Opening and Examining the Tutorial Solution In this lesson you will open the SQL Server Management Studio solution for the tutorial and review the projects and files. You will also review Object Explorer as it pertains to this tutorial. After you complete this lesson, you should be familiar with the solution and ready to start working with the solution files. Opening the Tutorial Solution First, let's open the tutorial solution you will be working with. To open the tutorial solution 1. In Windows Explorer, locate the Notification Services Tutorial folder. The default location for this folder is C:\Program Files\Microsoft SQL Server\90\Samples\Notification Services\tutorial. 2. Open the NSTutorial.ssmssln file. SQL Server Management Studio opens with solution files displayed in Solution Explorer. If Solution Explorer and Object Explorer do not appear, select them on the View menu. 3. Connect to the instance of the Database Engine where you want to store data for the instance of Notification Services. 1. In Object Explorer, click Connect and then select Database Engine. The Connect to Server dialog box appears. 2. In the Server name text box, select or enter the name of the Database Engine instance where you want to store Notification Services data for this tutorial.

3. In the Authentication text box, select an authentication mode. If you select SQL Server Authentication, you must enter a user name and password. 4. Click Connect. Examining the Tutorial Solution In Solution Explorer, you should see two projects: Tutorial and Weather. The Tutorial project contains files for the Tutorial instance of Notification Services. The Weather project contains files for the Weather application. The Tutorial instance hosts the Weather application.

Tutorial Project
First, expand the Tutorial project and expand the Miscellaneous folder. The Tutorial project contains only one file, TutorialICF.xml. This file describes the Tutorial instance of Notification Services.

Weather Project
Next, examine the Weather project. This project contains files used to update and run the Weather application and to review database changes after performing some tutorial lessons.

The Queries folder contains Transact-SQL queries that you will later use to review database changes and submit events to the Weather application. The Miscellaneous folder contains four files: o WeatherADF.xml is an application definition file (ADF). This file contains XML code that describes the Weather application. Most of the tutorial involves editing this file. o WeatherTransform.xslt is an Extensible Stylesheet Language Transformation (XSLT). The Weather application's XSLT content formatter uses the code in this file to transform raw notification data into formatted notifications. o AddSubscribers.vbs is a VBScript file used to add subscribers to the instance of Notification Services. Typically, you would build a subscription management interface using managed code, but this script is a quick way to load subscriber and subscription data for prototyping. o AddSubscriptions.vbs is a VBScript file used to add subscriptions to the Weather application. Again, script files like this are used primarily for prototyping.

Object Explorer In Object Explorer, you will be using the Notification Services and Databases folders. The Notification Services folder is where you will be accessing Notification Services

dialogs to create, update, register, enable, and start the instance of Notification Services. The Databases folder will contain the TutorialNSMain instance and TutorialWeather application database. Lesson 2: Performing an Initial Build of the Tutorial Instance Updated: 17 July 2006 In this lesson you will review the instance configuration file (ICF), update the ICF as needed, review the application definition file (ADF), and then create the Tutorial instance of Notification Services. Reviewing the ICF First, review the instance configuration in TutorialICF.xml. The instance configuration defines an instance of Notification Services, called Tutorial, that hosts the Weather application. During this tutorial, you will not be modifying TutorialICF.xml, but you should know what the file contains. To review the ICF 1. In Solution Explorer, expand Tutorial, and then expand Miscellaneous. 2. Double-click TutorialICF.xml. The ICF contains the following elements:
o o o

A ParameterDefaults element that contains default values for ICF and ADF parameters. An InstanceName element that specifies the Notification Services instance name, which is Tutorial. A SqlServerSystem element that specifies the instance of SQL Server that will host the Notification Services databases. The element contains a parameter, %_DBEngineInstance_%. The value for this parameter is provided by the parameter defaults, and can be overridden when you create or update the instance. An Applications element that contains basic information about the Weather application. This includes the application name, folder, ADF location, and the names and values of any replaceable parameters in the ADF. The Weather application uses two parameters: %_InstancePath_% and %_ServerName_%. Values for these parameters are provided by the parameter defaults, and can be overridden when you create or update the instance. A DeliveryChannels element that defines a delivery channel for the builtin File delivery protocol. The Weather application will use the File

delivery protocol to deliver notifications to the delivery channel named FileChannel. These notifications will be written to a file named FileNotifications.htm. Editing the ICF ParameterDefaults To make updating the tutorial easier, verify that the following values in the ParameterDefaults section of the ICF are correct:

The value for the _DBEngineInstance_ parameter must be the name of the Database Engine instance you are connected to in Object Explorer. The default value for this parameter is %COMPUTERNAME%, which is an environment variable that gets the name of the local computer. If you are connected to a named instance, replace %COMPUTERNAME% with the SQL Server instance name. For the default instance, the value should be the same as the computer name. The value for the _ServerName_ parameter should be the name of the local computer. This value is passed to the ADF, and specifies where the Notification Services engine components will run. Unless you are scaling-out the instance, which is not recommended for this tutorial, you should leave the value as %COMPUTERNAME%. The value for _InstancePath_ is the path to the TutorialICF.xml file. If you did not install the samples to the default location, update this value with the correct path of the tutorial files. %ProgramFiles% is an environment variable that gets the path of the Program Files folder on the local computer, which is typically C:\Program Files.

If you have changed any values in the ParameterDefaults section, save and close TutorialICF.xml. Reviewing the ADF Next, review the initial application definition in WeatherADF.xml. You will be modifying this file during the tutorial. To review the ADF 1. In Solution Explorer, expand Weather and then expand Miscellaneous. 2. Double-click WeatherADF.xml. The initial ADF is almost empty. It contains only those elements required for the application to build successfully. This includes an empty SubscriptionClasses element, an empty NotificationClasses element, and the SystemName elements for the application's generator and distributor. These elements contain a parameter, %_NSServer_%.The value for this parameter is provided when you create the instance of Notification Services and is passed from the ICF to the ADF.

Create the Instance of Notification Services When you create an instance of Notification Services, you provide Notification Services with the name of the ICF and values for any parameters needed by the ICF. Notification Services uses the ICF to create an instance database and uses the Weather application's ADF that is referenced in the ICF to create an application database. You will use SQL Server Management Studio to create the instance of Notification Services. To create the instance of Notification Services 1. In Object Explorer, right-click Notification Services and select New Notification Services Instance. 2. Click Browse, locate the TutorialICF.xml file, and then click Open. The default location for this file is C:\Program Files\Microsoft SQL Server\90\Samples\Notification Services\tutorial\TutorialICF.xml. 3. In the Parameters grid, review the values for the parameters. These should be the values you provided if you edited the ICF. If you are using the %COMPUTERNAME% and %ProgramFiles% environment variables, Notification Services shows the values for these variables, too. 4. Click OK. A dialog shows the status of the create actions. All actions should complete successfully. If the actions do not complete successfully, verify that the parameter values you provided are correct, and then try to create the instance of Notification Services again. 5. When the create actions complete, click Close. Review the Results After you create the Tutorial instance, you should see two new databases and an instance of Notification Services in Object Explorer. To review the results 1. In Object Explorer, expand Databases. You should see two databases: TutorialNSMain, which is the instance database, and TutorialWeather, which is the application database. If you do not see these databases, right-click Databases and select Refresh.

2. Expand Notification Services. You should see an instance of Notification Services named Tutorial. If you do not see the Tutorial instance, right-click Notification Services and select Refresh. Lesson 3: Adding an Event Class In this lesson you will add an event class to the application definition file (ADF) and then update the instance of Notification Services to apply the changes to the application database. You can then review the changes made to the application database. Event Class Primer An event class represents one type of event used by your Notification Services application. When you define an event class, you define a type of event that can be submitted to your application and used to generate notifications. The event class definition includes the event field names, data types, and type modifiers. An event class can define other information, such as indexes on the event data and supplemental tables. You can learn more about event classes by reading Defining Event Classes. When you create the application, Notification Services uses the event class definition to create tables, views, indexes, and stored procedures for storing, collecting, and managing event data. The WeatherData Event Class For this application, you will add a WeatherData event class to the ADF. This event class has five event fields, City, Date, Low, High, and Forecast. These describe the event data you will later submit to the application. For each event field, the event class defines the field name, data type, and field modifiers. To improve performance for notification generation, the event class also specifies an index on the City field of the WeatherData event class. Add the Event Class XML to the ADF The XML in this section defines the event class. Examine the XML and then follow the instructions to copy the XML to the ADF. To add the event class XML to the ADF 1. Click Copy Code to copy the XML to the Windows Clipboard. XML

Copy
<!-- Event Classes --> <EventClasses> <EventClass> <EventClassName>WeatherData</EventClassName> <Schema> <Field> <FieldName>City</FieldName> <FieldType>nvarchar(35)</FieldType> <FieldTypeMods>not null</FieldTypeMods> </Field> <Field> <FieldName>Date</FieldName> <FieldType>datetime</FieldType> <FieldTypeMods>not null</FieldTypeMods> </Field> <Field> <FieldName>Low</FieldName> <FieldType>float</FieldType> <FieldTypeMods>not null</FieldTypeMods> </Field> <Field> <FieldName>High</FieldName> <FieldType>float</FieldType> <FieldTypeMods>not null</FieldTypeMods> </Field> <Field> <FieldName>Forecast</FieldName> <FieldType>nvarchar(3500)</FieldType> <FieldTypeMods>not null</FieldTypeMods> </Field> </Schema> <IndexSqlSchema> <SqlStatement>CREATE INDEX myIndex ON WeatherData ( City ); </SqlStatement> </IndexSqlSchema> </EventClass> </EventClasses>

2. In Solution Explorer, open WeatherADF.xml. 3. Replace the following comment with the XML you just copied.
<!-- Replace with EventClasses XML -->

4. On the File menu, select Save WeatherADF.xml. Update the Instance of Notification Services After you modify the ADF, you update the instance of Notification Services to add event class objects to the application database.

To update the instance of Notification Services 1. In Object Explorer, expand Notification Services. 2. Right-click Tutorial, point to Tasks, and then select Update. 3. In the Update Instance dialog box, click Browse, locate and select the TutorialICF.xml file, and then click Open. 4. In the Parameters grid, review the values for the parameters. The values should be correct because you modified them as needed in Lesson 2. If you must edit these values, return to Lesson 2 to learn how to edit parameter defaults in the ICF. 5. Click OK. 6. Review the Notification Services - Update Summary dialog box, and then click Update. 7. When the update actions are complete, click Close. Review the Changes in the Application Database When you update the instance, Notification Services adds tables, views, and stored procedures for the event class in the TutorialWeather application database.

The dbo.WeatherData event view is the current set of events being processed by the application. When you later write notification generation queries, you select data from this view. The dbo.NSWeatherDataEvents table is the underlying table that contains event data for the event class. Event data stays in this table until it is removed by the vacuumer data removal process. Caution: Do not directly modify data in the application and instance databases. To add event data, you must use one of the supported event submission methods, such as the built-in event providers, event submission stored procedures, or the API. For more information, see Defining Event Providers.

You can use Object Explorer to examine these objects in the TutorialWeather database. You may have to refresh Object Explorer to see the new objects. Lesson 4: Adding a Notification Class In this lesson, you will add a notification class to the application definition file (ADF) and then update the instance of Notification Services to apply the changes to the application database. You can then review the changes made to the application database. Notification Class Primer

A notification class represents one type of notification produced by your Notification Services application. When you define a notification class, you define the following information:

Fields for the notification data, including the data types. These fields define the data you will be sending to subscribers. Information about the content formatter used to format notifications for the notification class. You can use the built-in Extensible Stylesheet Language Transformations (XSLT) content formatter, or you can use a custom content formatter. Information about how delivery protocols are to be used to deliver notifications.

You can also define optional settings such as digest or multicast delivery and the notification expiration age. For more information about notification classes, see Defining Notification Classes. When you create or update the application, Notification Services uses the notification class definition to create tables, views, indexes, and stored procedures for storing and managing notification data. When you create the notification table and view, Notification Services adds the following fields: SubscriberId, DeviceName, and SubscriberLocale. These fields are required by Notification Services, and are described in later lessons. The WeatherAlerts Notification Class For this application, you will add a WeatherAlerts notification class to the ADF. This notification class has five notification fields, an XSLT content formatter, and a File delivery protocol.

The notification fields are City, Date, Low, High, and Forecast. In this application, the notification class fields match the event class fields, but this is not required. When Notification Services distributes the notifications, it will format the raw data into a customized message using the built-in XSLT content formatter. The XSLT file name is WeatherTransform.xslt, and the file location is defined by the %_AppPath_% parameter; the value for this parameter is provided in the ICF. For more information about the XSLT content formatter, see XSLT Content Formatter. After formatting, Notification Services will deliver the notifications to a file by using the built-in File delivery protocol. The file name and location are defined in the DeliveryChannels element of the ICF. Protocol definitions can contain field definitions for message headers, such as those required by SMTP, and protocol execution settings to configure retry, failure, and time-out settings. The File protocol does not use these settings, but most other protocols use header fields.

Note: The File delivery protocol is intended primarily for prototyping and testing. Add the Notification Class XML to the ADF The XML in this section defines the notification class. Examine the XML and then follow the instructions to copy the XML to the ADF. Add the Notification Class XML to the ADF 1. Click Copy Code to copy the XML to the Windows Clipboard. XML Copy
<!-- Notification Classes --> <NotificationClasses> <NotificationClass> <NotificationClassName> WeatherAlerts</NotificationClassName> <Schema> <Fields> <Field> <FieldName>City</FieldName> <FieldType>nvarchar(35)</FieldType> </Field> <Field> <FieldName>Date</FieldName> <FieldType>datetime</FieldType> </Field> <Field> <FieldName>Low</FieldName> <FieldType>float</FieldType> </Field> <Field> <FieldName>High</FieldName> <FieldType>float</FieldType> </Field> <Field> <FieldName>Forecast</FieldName> <FieldType>nvarchar(3500)</FieldType> </Field> </Fields> </Schema> <ContentFormatter> <ClassName>XsltFormatter</ClassName> <Arguments> <Argument> <Name>XsltBaseDirectoryPath</Name> <Value>%_AppPath_%</Value> </Argument> <Argument> <Name>XsltFileName</Name>

<Value>WeatherTransform.xslt</Value> </Argument> </Arguments> </ContentFormatter> <Protocols> <Protocol> <ProtocolName>File</ProtocolName> </Protocol> </Protocols> </NotificationClass> </NotificationClasses>

2. In Solution Explorer, open WeatherADF.xml. 3. Replace the following XML with the XML you just copied.
<!-- Notification Classes --> <NotificationClasses></NotificationClasses>

4. On the File menu, select Save WeatherADF.xml. Update the Instance of Notification Services After you modify the ADF, you update the instance of Notification Services to add notification class objects to the application database: To update the instance of Notification Services 1. In Object Explorer, expand Notification Services. 2. Right-click Tutorial, point to Tasks, and then select Update. 3. In the Update Instance dialog box, click Browse, locate the TutorialICF.xml file, and then click Open. 4. In the Parameters grid, review the values for the parameters. Use the same values you used to create the instance. 5. Click OK. 6. Review the Notification Services - Update Summary dialog box, and then click Update. 7. When the update actions are complete, click Close. Review the Database Changes When you update the instance, Notification Services adds tables, views, and stored procedures for the notification class in the TutorialWeather application database.

The dbo.WeatherAlerts view is where the notification generation rules will insert notifications.

The dbo.NSWeatherAlertsFileNotifications view contains notifications from the WeatherAlerts notification class sent using the File delivery protocol. This view is for internal use only. The dbo.NSWeatherAlertsNotificationDistribution view combines data from several internal Notification Services tables to provide information about notification distribution attempts. The dbo.NSWeatherAlertsNotifications table is the underlying table that contains notification data for the notification class. Notification data stays in this table until it is removed by the vacuumer data removal process. This table is for internal use only. Caution: Do not directly modify data in the notification tables and views.

You can use Object Explorer to examine these objects in the TutorialWeather database. Tables and views for internal use only contain data that is used for internal operations; you do not have to understand this data. You may have to refresh Object Explorer to see the new objects. Lesson 5: Adding a Subscription Class In this lesson, you will add a subscription class to the application definition file (ADF) and then update the instance of Notification Services to apply the changes to the application database. You can then review the changes made to the application database. Subscription Class Primer When you define a subscription class, you are defining storage for subscription data and queries that generate notifications from event and subscription data. When defining storage for subscription data, you define fields for the subscription data you collect. For example, if part of the subscription data is a city of interest, you can add a City subscription field. Then, you provide an interface to let subscribers create subscriptions in which they specify a city. If your application supports multiple subscriber locales and multiple devices, such as email and cellular phones, you also can add DeviceName and SubscriberLocale fields to the subscription fields. These fields let you customize notifications for different devices, time zones, and languages. Notification Services adds a SubscriberId field to the underlying table for each subscription class. Besides defining subscription fields, you must also define a notification generation rule. This rule is a Transact-SQL query that matches event and subscription data and inserts

the results into the notification class view. These rules can be event driven or scheduled. Event-driven rules run whenever events arrive. Scheduled rules evaluate individual subscriptions on a schedule provided in the subscription. A subscription class can define other information, such as indexes on the subscription data and supplemental tables. For more information about subscription classes, see Defining Subscription Classes. When you create the application, Notification Services uses the subscription class definition to create tables, views, indexes, and stored procedures for the subscription class. The WeatherCity Subscription Class For this application, you will add a WeatherCity subscription class to the ADF. This subscription class has three fields, DeviceName, SubscriberLocale, and City. The City field is the important field for this application. When subscribers create weather subscriptions, they must specify the name of a city. The DeviceName and SubscriberLocale subscription fields are defined so that you can add support for multiple devices and locales. This subscription class also defines a notification generation query. To write this query, you must know what event data is available, what notification data you want to produce, and what subscription data is available:

As shown in Lesson 3, the WeatherData event class has five fields: City, Date, Low, High, and Forecast. The subscription class has a City field. As shown in Lesson 4, the WeatherAlerts notification class has the same fields as the event class (City, Date, Low, High, and Forecast). Also, remember that the underlying notification table has the following fields: SubscriberId, DeviceName, and SubscriberLocale.

These fields become columns in views. Knowing these fields, you can join the event and subscription views and insert data into the notification view: XML Copy

INSERT INTO WeatherAlerts(SubscriberId, DeviceName, SubscriberLocale, City, Date, Low, High, Forecast) SELECT s.SubscriberId, s.DeviceName, s.SubscriberLocale, e.City, e.Date, e.Low, e.High, e.Forecast FROM WeatherData e, WeatherCity s WHERE e.City = s.City;

When Notification Services runs this query, it joins the current set of events in the event class view with the subscriptions in the subscription class view based on matches between the event and subscription City values. Notification Services then inserts the results into the notification view. Add the Subscription Class to the ADF The XML in this section defines the subscription class. Examine the XML and then follow the instructions to copy the XML to the ADF. To add the subscription class to the ADF 1. Click Copy Code to copy the XML to the Windows Clipboard. XML Copy
<!-- Subscription Classes --> <SubscriptionClasses> <SubscriptionClass> <SubscriptionClassName>WeatherCity</SubscriptionClassName> <Schema> <Field> <FieldName>DeviceName</FieldName> <FieldType>nvarchar(255)</FieldType> <FieldTypeMods>not null</FieldTypeMods> </Field> <Field> <FieldName>SubscriberLocale</FieldName> <FieldType>nvarchar(10)</FieldType> <FieldTypeMods>not null</FieldTypeMods> </Field> <Field> <FieldName>City</FieldName> <FieldType>nvarchar(40)</FieldType> <FieldTypeMods>not null</FieldTypeMods> </Field> </Schema> <EventRules> <EventRule> <RuleName>WeatherEventRule</RuleName> <EventClassName>WeatherData</EventClassName> <Action> INSERT INTO WeatherAlerts(SubscriberId, DeviceName, SubscriberLocale, City, Date, Low, High, Forecast) SELECT s.SubscriberId, s.DeviceName, s.SubscriberLocale, e.City, e.Date, e.Low, e.High, e.Forecast FROM WeatherData e, WeatherCity s WHERE e.City = s.City; </Action>

</EventRule> </EventRules> </SubscriptionClass> </SubscriptionClasses>

2. In Solution Explorer, open WeatherADF.xml. 3. Replace the following XML with the code you just copied.
<!-- Subscription Classes --> <SubscriptionClasses></SubscriptionClasses>

4. On the File menu, select Save WeatherADF.xml. Update the Instance of Notification Services After you modify the ADF, you update the instance of Notification Services to add subscription class objects to the application database. To update the instance of Notification Services 1. In Object Explorer, expand Notification Services. 2. Right-click Tutorial, point to Tasks, and then select Update. 3. In the Update Instance dialog box, click Browse, locate the TutorialICF.xml file, and then click Open. 4. In the Parameters pane, review the parameter values. 5. Click OK. 6. Review the Notification Services - Update Summary dialog box, and then click Update. 7. When the update actions complete, click Close. Review the Changes in the Application Database When you update the instance, Notification Services adds tables, views, and stored procedures for the subscription class in the TutorialWeather application database:

The dbo.WeatherCityView view provides a view of the subscription records for the associated subscription class. The dbo.WeatherCity view contains the current set of subscriptions being evaluated by the application. In your notification generation query, you select subscription data from this view. The dbo.NSWeatherCitySubscriptions table is the underlying table that contains subscription data for the subscription class. Caution: Do not directly modify the data in the subscription tables and views. Use the

subscription management objects. For more information, see Developing Subscription Management Interfaces. You can use Object Explorer to examine these objects in the TutorialWeather database. Tables and views for internal use only contain data used for internal tracking and data lookup. You may have to refresh Object Explorer to see the new objects. Lesson 6: Adding an Event Provider In this lesson, you will configure a non-hosted event provider that you will later use when you submit events to the Weather application. You will then update the instance of Notification Services to apply the changes to the application database. Event Provider Primer Event providers collect event data and submit it to Notification Services. When an event provider submits a set of events, it submits the events to an event class view. The set of events, called an event batch, is inserted into the event class view. Each event then becomes a row in the underlying event class table. To help you develop and deploy a Notification Services application quickly, Notification Services includes three standard hosted event providers, a file system watcher, the SQL Server event provider, and the Analysis Services event provider. Using these event providers, you can easily gather events from an XML file, gather events using a TransactSQL query, and gather events using an MDX query. The Notification Services engine hosts all these event providers. This means that the Notification Services engine starts and runs hosted event providers. You can use the standard event providers in your application by specifying predefined names and custom operational parameters in the application definition. For more information, see Defining Event Providers. If the standard event providers do not meet the needs of your application, you can develop event providers that are customized to your environment and event sources. The Notification Services engine can host your custom event providers, or they can be nonhosted. Non-hosted event providers are stand-alone applications that submit events to a notification application without being hosted by the Notification Services engine. When you define a non-hosted event provider, you give the non-hosted event provider a name in the ADF. This name is used for tracking and troubleshooting event collection. The WeatherSPEventProvider Event Provider

For this application, you will add a non-hosted event provider to the ADF. As mentioned earlier, you will just provide a name for this event provider so that you can later determine which events it submitted to the application. The name of the event provider will be WeatherSPEventProvider. You will later use stored procedures to submit events to the Weather application, and you will use the name WeatherSPEventProvider when submitting those events. Add the Provider Code to the ADF The XML in this section defines the non-hosted event provider. Examine the XML and then follow the instructions to copy the XML to the ADF. To add the provider code to the ADF 1. Click Copy Code to copy the XML to the Windows Clipboard. XML Copy
<!-- Event Providers --> <Providers> <NonHostedProvider> <ProviderName>WeatherSPEventProvider</ProviderName> </NonHostedProvider> </Providers>

2. In Solution Explorer, open WeatherADF.xml. 3. Replace the following comment with the XML you just copied.
<!-- Replace with Providers XML -->

4. On the File menu, select Save WeatherADF.xml. Update the Instance of Notification Services After you modify the ADF, you update the instance of Notification Services to add the event provider definition to the application database. To update the instance of Notification Services 1. In Object Explorer, expand Notification Services. 2. Right-click Tutorial, point to Tasks, and then select Update. 3. In the Update Instance dialog box, click Browse, locate the TutorialICF.xml file, and then click Open.

4. In the Parameters grid, review the values for the parameters. Use the same values you used to create the instance. 5. Click OK. 6. Review the Notification Services - Update Summary dialog box, and then click Update. 7. When the update actions complete, click Close. Review the Changes in the Application Database When you update the instance, Notification Services adds information about the event provider to the NSProviders table in the TutorialWeather application database. To view TutorialWeather event providers 1. In Solution Explorer, expand Weather, and then expand Queries. 2. Double-click ViewEventProviders.sql. You may have to connect to the instance of the Database Engine. 3. Press F5 to run the Transact-SQL query. Lesson 7: Configuring the Generator and Distributor Updated: 5 December 2005 In this lesson, you will review generator and distributor settings in the application definition file (ADF) and then modify and update the distributor settings. Generator and Distributor Primer The generator that is run by the Notification Services engine governs the rule processing for a notification application. Settings for the generator determine which computer runs the generator and how many threads the generator can use when it processes application rules. Each application has one generator. For more information about generators, see Specifying Generator Settings. Distributors, which are also run by the Notification Services engine, govern notification formatting and delivery. On a configurable interval, called a distributor quantum, the distributor looks for a group of notifications, called a work item, to process. If a work item is available, the distributor acquires the work item, calls the content formatter to transform the notification data, and then sends the formatted notifications using a delivery protocol.

Each application can have one or more distributors, with a maximum of one distributor per application per computer. For more information about distributors, see Specifying Distributor Settings. Weather Application Generators and Distributors For purposes of this application, the generator and distributor will run on the local computer, and you will use the default thread pool settings. Notice that the system name value for the generator and the distributor in the XML is %_NSServer_%. You provide a value for this parameter through the instance configuration file (ICF) when you create or update the instance. In this lesson, you will simply add a polling interval for the distributor; the polling interval defines how frequently the distributor looks for work items. This interval will be 15 seconds. This is PT15S in the XML duration format. Modify the Distributor ADF Code The XML in this section defines the distributor for the Weather application. Examine the XML and then follow the instructions to copy the XML to the ADF. To modify the distributor ADF code 1. Click Copy Code to copy the XML to the Windows Clipboard. XML Copy
<QuantumDuration>PT15S</QuantumDuration>

2. In Solution Explorer, open WeatherADF.xml. 3. Replace the following XML comment with the XML you just copied. Copy
<!-- Paste QuantumDuration here -->

Notice that the only line of code you are adding is the distributor's QuantumDuration element and value. If you prefer, you can just add that line of XML to the ADF. 4. On the File menu, click Save WeatherADF.xml.

Update the Instance of Notification Services After you modify the ADF, you update the instance of Notification Services to modify distributor settings in the application database. To update the instance of Notification Services 1. In Object Explorer, expand Notification Services. 2. Right-click Tutorial, point to Tasks, and then click Update. 3. In the Update Instance dialog box, click Browse, locate the TutorialICF.xml file, and then click Open. 4. In the Parameters pane, review the values for the parameters. Use the same values you used to create the instance. 5. Click OK. 6. Review the Notification Services - Update Summary dialog box, and then click Update. 7. When the update is completed, click Close. Lesson 8: Altering Application Execution Settings In this lesson you will configure application execution settings in the application definition file (ADF) and then update the instance of Notification Services to apply the changes to the application database. Application Execution Settings Notification Services provides several application execution settings for tuning your application. These settings control how frequently data is processed, how far the generator is allowed to fall behind the real-time clock, how events are processed, how much data can be received and sent, how distribution data is logged, and how frequently old data is removed from the database. For more information about these settings, see Specifying Application Execution Settings. Application Execution Settings for the Weather Application For this application, you will configure three application execution settings: the generator quantum, distributor logging, and the data removal interval. You should configure these settings in every application.

You will set the quantum duration to 15 seconds. This is PT15S in the XML duration format. This configures the generator to fire subscription rules every 15 seconds. In your applications, this quantum duration might be longer. For more information, see Specifying the Generator Quantum Duration.

You will turn off distributor logging to minimize the data logged to the application database per notification. You may want to enable distributor logging during application development, but you should turn off all or most distributor logging when you deploy your applications. For more information, see Configuring Distributor Logging. You will specify a data removal interval so that older event, notification, and distribution data is regularly removed from the application database. The vacuuming schedule specifies that data older than one day can be deleted from the database, and that the data removal process runs at 23:00:00 UTC. For more information, see Configuring Data Removal.

Add the Application Execution Settings Code to the ADF The XML in this section configures application execution settings as described earlier. Examine the XML and then follow the instructions to copy the XML to the ADF. To add the application execution settings code to the ADF 1. Click Copy Code to copy the code to the Windows Clipboard. XML Copy
<!-- ApplicationExecutionSettings --> <ApplicationExecutionSettings> <QuantumDuration>PT15S</QuantumDuration> <DistributorLogging> <LogBeforeDeliveryAttempts>false</LogBeforeDeliveryAttempts> <LogStatusInfo>false</LogStatusInfo> <LogNotificationText>false</LogNotificationText> </DistributorLogging> <Vacuum> <RetentionAge>P1D</RetentionAge> <VacuumSchedule> <Schedule> <StartTime>23:00:00</StartTime> <Duration>P0DT02H00M00S</Duration> </Schedule> </VacuumSchedule> </Vacuum> </ApplicationExecutionSettings>

2. In Solution Explorer, open WeatherADF.xml. 3. Replace the following comment with the code you just copied.
<!-- Replace with ApplicationExecutionSettings XML -->

4. On the File menu, click Save WeatherADF.xml.

Update the Instance of Notification Services After you modify the ADF, update the instance of Notification Services to modify the application execution settings in the application database. To update the instance of Notification Services 1. In Object Explorer, expand Notification Services. 2. Right-click Tutorial, point to Tasks, and then select Update. 3. In the Update Instance dialog box, click Browse, locate the TutorialICF.xml file, and then click Open. 4. In the Parameters pane, enter values for the parameters. Use the same values you used to create the instance. 5. Click OK. 6. Review the Notification Services - Update Summary dialog box, and then click Update. 7. When the update is completed, click Close. 8. You can now close WeatherADF.xml. Lesson 9: Registering, Enabling, and Starting the Instance Updated: 17 July 2006 In this lesson, you will configure security for the instance of Notification Services and register the instance of Notification Services that installs the Notification Services engine. Then, you will enable and start the instance. The Notification Services Engine Earlier in this tutorial, you configured a generator and a distributor for the application. These components are run by the Notification Services engine. If the application had used a hosted event provider, that event provider also would be run by the Notification Services engine. The Notification Services engine is either a Windows service that you create when you register the instance on a computer, or a process hosted by a custom application. When you configure hosted event providers, generators, and distributors in the application definition file (ADF), you specify a system name, which is the computer where that component runs. You must install and run the Notification Services engine on each computer specified by the system name values in the ADF. When you start the Notification Services engine, it connects to the instance and application databases to determine what components it runs and if those components are enabled. The engine then runs its enabled components.

For more information about the Notification Services engine, see Controlling Instance and Application Operation. The Notification Services engine connects to the instance and application databases and runs its stored procedures. To run these stored procedures, the engine must have login access to the server and the correct database permissions. These permissions are granted to the login through membership in database roles in the instance and application databases. For more information, see Configuring SQL Server Permissions for an Instance of Notification Services. The Engine for the Weather Application For this tutorial, you will run the Notification Services engine as a Windows service. You will install the Windows service, named NS$Tutorial, when you register the instance of Notification Services. You will register the instance locally. This is the same computer name you provide for the _NSServer_ parameter when you create or update the instance of Notification Services. When you register the instance, you must provide a Windows user name and password. The Windows service can use its Windows account or a SQL Server login you specify to log in to the database server. You must add a user for the Windows account or SQL Server login to the TutorialNSMain and TutorialWeather databases and then add the user to database roles. You use this same account when you register the instance of Notification Services. For more information about the security model, see Security Considerations for Notification Services. After you register the instance and configure security, you will enable and start the instance of Notification Services. Configure Database Permissions for the Windows Service Use the following steps to configure database permissions for the account used by the Windows service to connect to the TutorialNSMain and TutorialWeather databases. To configure database permissions for the Windows service 1. Choose a Windows account for the NS$Tutorial Windows service. When you deploy an instance of Notification Services, use an account that has few privileges, and then grant only the necessary permissions to that account. 2. If you can use Windows Authentication, make sure this Windows account can log in to the database server. If you cannot use Windows Authentication, make sure there is a SQL Server login that the Windows service can use.

To add a new login in Object Explorer, expand Security, right-click Logins, and select New Login. You can add Windows accounts or create SQL Server login accounts using this dialog box. 3. Using Object Explorer, create a database user for the login in the TutorialNSMain database and make the user a member of the NSRunService database role: 1. Expand Databases, and then expand the TutorialNSMain database. 2. Right-click Security, point to New, and then select User. 3. In the User name box, enter a name for the database user. The database user name is typically the same as the login name. 4. In the Login name box, enter the name of the login that is used by the NS$Tutorial Windows service. The login name must exactly match the name of an existing login in the instance of the Database Engine. Click the browse (...) button to search for the login name. 5. In the Database role membership box, click NSRunService. 6. Click OK. 4. Create a database user for the login in the TutorialWeather database, and make the user a member of the NSRunService database role: 1. Expand the TutorialWeather database. 2. Right-click Security, point to New, and then select User. 3. In the User name box, enter a name for the database user. The database user name is typically the same as the login name. 4. In the Login name box, enter the name of the login that is used by the NS$Tutorial Windows service. The login name must exactly match the name of an existing login in the instance of the Database Engine. Click the browse ( ... ) button to search for the login name. 5. In the Database role membership box, click NSRunService. 6. Click OK. Configure Folder Permissions for the Windows Service Because the Weather application uses the File delivery protocol to deliver notifications, you must also make sure that the Windows service account has permissions in the folder where it writes notifications. To configure folder permissions for the Windows service 1. Open Windows Explorer. 2. Locate the Notification Services Tutorial folder. The default location for this folder is C:\Program Files\Microsoft SQL Server\90\Samples\Notification Services\tutorial.

3. Expand the Tutorial folder, and then expand the Weather folder. 4. Right-click the Notifications folder and select Sharing and Security. 5. On the Security tab, verify that the Windows account used by the NS$Tutorial Windows service has write permissions. Register the Instance and Create a Windows Service Use the following steps to register the instance of Notification Services locally and install the NS$Tutorial Windows service. During this step, Notification Services grants Windows permissions to the service account. Register the instance and create a Windows service 1. 2. 3. 4. 5. In Object Explorer, expand Notification Services. Right-click Tutorial, point to Tasks, and select Register. Select the Create Windows service check box. Enter the login account and password for the NS$Tutorial Windows service. If you use SQL Server Authentication to access databases, select SQL Server Authentication and enter the SQL Server login and password. Otherwise, leave Windows Authentication selected. 6. Click OK to register the instance, create the Windows service, and create performance counters. 7. When the registration is complete, click Close. Enable and Start the Tutorial Instance Use the following steps to enable the Tutorial instance and start the NS$Tutorial Windows service. To enable and start the tutorial instance 1. In Object Explorer, right-click Tutorial and select Enable. 2. Right-click Tutorial, and select Start. If the service does not start, either the service does not have a valid Windows account, it does not have the necessary permissions, or it cannot connect to the TutorialNSMain or TutorialWeather database. Verify that the account that is used by the service has the permissions that were discussed earlier. For more information, see Securing Notification Services. Checking Tutorial Instance Status To verify that the application is configured correctly and that the Tutorial instance is enabled and started, view the status of the Tutorial instance. To check tutorial instance status

1. Right-click the instance and select Properties. On the Applications page, you can view the status of all application components. In the Current Status column, all components should show Enabled. If the status is Enable Pending, wait 30 seconds and then click Refresh. If the status is still Enable Pending, the system name of the component does not match the name of the computer where the Notification Services engine is running. Verify that the Server values on the Application page and the Windows Services page match. On the Windows Services page, you can verify that the NS$Tutorial Windows service is running and, in the Associated components box, you can view which components are enabled on the Windows service. You should see one generator and one distributor. Next Lesson Even though the Tutorial instance is enabled and running, it will not produce notifications until you have added subscribers, subscriptions, and events. In the next lesson, you will add subscribers and subscriptions. Lesson 10: Adding Subscribers and Subscriptions In this lesson, you will review two VBScript files to understand how they submit subscriber and subscription data to Notification Services, and then you will run the scripts to add subscriber data to the instance database and subscription data to the application database. Subscriber and Subscription Management Notification Services generates notifications based on subscriptions created by subscribers. These subscribers can be people or other applications. As part of developing a Notification Services application, you develop one or more interfaces so that subscribers can manage their subscriptions. Subscriber data includes a subscriber ID and information about the subscriber's devices, such as e-mail addresses and text messaging addresses. Each subscriber can have multiple devices. Subscriber data is stored in instance database objects. All applications hosted by an instance of Notification Services use the same subscriber data. Subscription data specifies what application information the subscriber is interested in, such as the city for weather forecasts, and which device receives the notifications. Your

application might have built-in logic to select subscriber devices based on conditional logic, such as day, time, or message importance. Subscription data is stored in application databases. Each application has its own subscription data. Most Notification Services applications provide an interface that subscribers can use to manage their subscriber and subscription data. This is frequently an ASP.NET application, but can be a Windows application, Web service, or any other interface you want to develop using the Notification Services subscription management objects. For more information, see Developing Subscription Management Interfaces. Review the Weather Subscription Management Interface For simplicity, the Weather application bulk loads its subscriber and subscription data using two VBScript files. This is not a common way to manage subscribers and subscriptions, but is useful for prototyping and testing your notification applications. These scripts illustrate how you can call Notification Services interfaces from COM components. Notification Services is written in managed code (C#) and is designed to be accessible from both managed and unmanaged code.

AddSubscribers.vbs
The first VBScript, called AddSubscribers.vbs, adds three subscribers to the Weather instance. First, create NSInstance and Subscriber objects: Copy
Dim nsInstance, nsSubscriber, nsSubscriberDevice ' Create and initialize NSInstance object. Set nsInstance = WScript.CreateObject("Microsoft.SqlServer.NotificationServices.NSInstan ce") nsInstance.Initialize "Tutorial" ' Create and initialize NSSubscriber object. Set nsSubscriber = WScript.CreateObject("Microsoft.SqlServer.NotificationServices.Subscrib er") nsSubscriber.Initialize (nsInstance)

Next, add three subscribers using the Subscriber object: Copy


' Add subscribers. nsSubscriber.SubscriberId = "stephanie" nsSubscriber.Add

nsSubscriber.SubscriberId = "david" nsSubscriber.Add nsSubscriber.SubscriberId = "richard" nsSubscriber.Add

Finally, create a SubscriberDevice object and add subscriber devices for each subscriber: Copy
' Create NSSubscriberDevice object. Set nsSubscriberDevice = WScript.CreateObject("Microsoft.SqlServer.NotificationServices.Subscrib erDevice") nsSubscriberDevice.Initialize (nsInstance) ' DeviceName must match subscriptions that use this device nsSubscriberDevice.DeviceName = "myDevice" ' Add a file device for each subscriber nsSubscriberDevice.SubscriberId = "stephanie" nsSubscriberDevice.DeviceTypeName = "File" nsSubscriberDevice.DeviceAddress = "stephanie@adventure-works.com" nsSubscriberDevice.DeliveryChannelName = "FileChannel" nsSubscriberDevice.Add nsSubscriberDevice.SubscriberId = "david" nsSubscriberDevice.DeviceTypeName = "File" nsSubscriberDevice.DeviceAddress = "david@adventure-works.com" nsSubscriberDevice.DeliveryChannelName = "FileChannel" nsSubscriberDevice.Add nsSubscriberDevice.SubscriberId = "richard" nsSubscriberDevice.DeviceTypeName = "File" nsSubscriberDevice.DeviceAddress = "richard@adventure-works.com" nsSubscriberDevice.DeliveryChannelName = "FileChannel" nsSubscriberDevice.Add

AddSubscriptions.vbs
The other VBScript, called AddSubscriptions.vbs, adds one subscription for each of our three subscribers. First, create and initialize the NSInstance, NSApplication, and Subscription objects: Copy
Dim nsInstance, nsApplication, nsSubscription ' Create NSInstance object. Set nsInstance = WScript.CreateObject("Microsoft.SqlServer.NotificationServices.NSInstan ce") nsInstance.Initialize "Tutorial" ' Create NSApplication object.

Set nsApplication = WScript.CreateObject("Microsoft.SqlServer.NotificationServices.NSApplic ation") nsApplication.Initialize (nsInstance), "Weather" ' Create Subscription object. Set nsSubscription = WScript.CreateObject("Microsoft.SqlServer.NotificationServices.Subscrip tion") nsSubscription.Initialize (nsApplication), "WeatherCity"

Next, set the common properties for all subscriptions you are loading: Copy
nsSubscription.SetFieldValue "DeviceName", "myDevice" nsSubscription.SetFieldValue "SubscriberLocale", "en-us"

Finally, add the subscriptions: Copy


nsSubscription.SubscriberId = "stephanie" nsSubscription.SetFieldValue "City", "Seattle" nsSubscription.Add nsSubscription.SubscriberId = "david" nsSubscription.SetFieldValue "City", "Orlando" nsSubscription.Add nsSubscription.SubscriberId = "richard" nsSubscription.SetFieldValue "City", "Seattle" nsSubscription.Add

Load Subscriber and Subscription Data Now that you are familiar with the scripts, use them to load subscriber data into the Tutorial instance and subscription data into the Weather application. To load subscriber and subscription data 1. Using Windows Explorer, locate the tutorial Weather folder. The default location for this folder is C:\Program Files\Microsoft SQL Server\90\Samples\Notification Services\tutorial\Weather. 2. Double-click AddSubscribers.vbs. You should receive the message, "Subscribers successfully added." 3. Double-click AddSubscriptions.vbs. You should receive the message, "Subscriptions successfully added." Note:

If you install Notification Services 2.0 after you install SQL Server 2005 Notification Services, the wrong versions of the assemblies will be registered for COM interop and these scripts will not work. For more information, see How to: Register the Core Notification Services Assembly for COM Interop. View Subscriber Data After you add subscriber data to the application, you can view the subscriber and device information using the ViewSubscribersAndDevices.sql query. To view subscriber data 1. In Solution Explorer, expand Weather, expand Queries, and then double-click ViewSubscribersAndDevices.sql. 2. Press F5 to run the query. You should see subscriber and device information for three subscribers. 3. Close ViewSubscribersAndDevices.sql. View Subscription Data After you add subscription data to the application, you can view the subscriptions information using the ViewSubscriptions.sql query. To view subscription data 1. In Solution Explorer, double-click ViewSubscriptions.sql. 2. Press F5 to run the query. You should see three subscriptions, one for each subscriber. 3. Close ViewSubscriptions.sql. Lesson 11: Submitting Events to the Weather Application In this step, you will use a Transact-SQL script to submit events to the Weather application, and then view the resulting notifications. Event Data Events are data that your notification application uses to generate notifications. The notification generation queries you write join event data and subscription data to produce notifications, such as the query in Lesson 5 The queries that generate notifications are fired during each generator quantum that has data to process. Event rules run in any quantum in which one or more event batches

arrived. Scheduled rules run in any quantum that has scheduled subscriptions expected to be processed. If there is no event data, there is no reason to run rules. Therefore, no notifications are produced. WeatherData Events For this application, you will submit a batch of events using the event-submission stored procedures. First, you will use the NSEventBeginBatchWeatherData stored procedure to open an event batch. You will specify the WeatherSPEventProvider non-hosted event provider as the event provider, which you defined in Lesson 6. Caution: Do not run these statements individually. They open and close an event batch, and must run in the same transaction. To run these queries, run the AddWeatherEvents.sql script, as documented later in this lesson. Copy
-- Use the weather application's database. USE TutorialWeather; -- Start an event batch. DECLARE @BatchID bigint; EXEC dbo.NSEventBeginBatchWeatherData N'WeatherSPEventProvider', @BatchID OUTPUT;

After creating the event batch, you use the NSEventWriteWeatherData stored procedure to add three weather events. You must provide the event batch ID and then provide values for the event fields. This is one sample event: Copy
-- Submit events. EXEC dbo.NSEventWriteWeatherData @EventBatchId=@BatchID, @City=N'Seattle', @Date=CONVERT(DATETIME, '2005-04-20 13:00:00', 120), @Low = 31, @High = 52, @Forecast=N'Sunny'

After you use this stored procedure to submit three events, you will use the NSEventFlushBatchWeatherData to close the event batch and submit it to the application database. Copy
-- Flush event batch. EXEC dbo.NSEventFlushBatchWeatherData @BatchID;

You can display the event batch ID so that you can use views and stored procedures to view information about the event batch.

Copy
-- Display event batch ID SELECT @BatchID 'Event Batch';

Submit Events to the Weather Application Use the AddWeatherEvents.sql query to add events to the Weather application. To submit events to the Weather application 1. In Solution Explorer, expand Weather, expand Queries, and then open AddWeatherEvents.sql. 2. Review the Transact-SQL code. 3. Press F5 to run the query. You should receive two result sets. The first result set returns an EventCount value of 3. The second result set returns an event batch ID of 1. View Event Data Use the ViewWeatherEvents.sql query to view the events you just added. To view event data 1. In Solution Explorer, open ViewWeatherEvents.sql. 2. Review the Transact-SQL code. 3. Press F5 to run the query. If you submitted multiple event batches, change the EventBatchId parameter as appropriate. View Notifications After about 30 seconds, Notification Services should have created a FileNotifications.htm file in the Notifications folder. Open this file to view the notification data. You should receive three notifications similar to the following:

Notification Id: 1 Notification Class Name: WeatherNotifications Subscriber Id: stephanie Device Address: stephanie@adventure-works.com Protocol Fields: Body: Weather report for the city of Seattle [2/21/2005 2:01:00 PM]: Sunny Expected low temperature : 31 F. Expected high temperature: 52 F. For more information, visit our web site at http://www.msnbc.com/news/wea_front.asp?ta=y&tab=BW&tp=&czstr=Seattle Thank you for using SQL Server Notification Services. Notification Id: 2 Notification Class Name: WeatherNotifications Subscriber Id: david Device Address: david@adventure-works.com Protocol Fields: Body:

Weather report for the city of Orlando [2/22/2005 2:01:00 AM]: Partly Cloudy Expected low temperature : 59 F. Expected high temperature: 81 F. For more information, visit our web site at http://www.msnbc.com/news/wea_front.asp?ta=y&tab=BW&tp=&czstr=Orlando Thank you for using SQL Server Notification Services. Notification Id: 3 Notification Class Name: WeatherNotifications Subscriber Id: richard Device Address: richard@adventure-works.com Protocol Fields: Body: Weather report for the city of Seattle [2/21/2005 2:01:00 PM]: Sunny Expected low temperature : 31 F. Expected high temperature: 52 F. For more information, visit our web site at http://www.msnbc.com/news/wea_front.asp?ta=y&tab=BW&tp=&czstr=Seattle Thank you for using SQL Server Notification Services.

Because you are using the built-in File delivery protocol, all three notifications generated from the events are in one file. If you submit more events, the additional notifications will be appended to this file. Also notice that there is a header for each notification. This shows you information about the notification, including the subscriber ID and device address. The actual text of the notification starts after "Body:". Troubleshooting If you do not see the FileNotifications.htm file in the Notifications folder within one minute, look in the Application log in Windows Event Viewer for events from Notification Services. The Windows service may not have permission to write to the Notifications folder. You can view information about any notifications generated for the WeatherNotifications notification class by running the ViewNotifications.sql query. To view notification information 1. In Solution Explorer, expand Weather, expand Queries, and then double-click ViewNotifications.sql. 2. Press F5 to run the query. Look in the DeliveryStatusDescription column for information about notification delivery. If there are any failures, additional information should be provided in the Application log. 3. Close ViewSubscribersAndDevices.sql. What's Next?

This tutorial has shown you how to build a simple prototype for a Notification Services application. To continue learning about Notification Services, use the following resources:

Building Notification Solutions SQL Server Notification Services Samples

Você também pode gostar