Home > Articles

  • Print
  • + Share This
This chapter is from the book

Running the Stock Application

In this section, we'll compile, register, and enable the application; start its engine running; and then feed it sample data. We'll submit events and subscriptions as described earlier and then observe the notification data written to the output file.

Assuming that your development environment is set up as described in Chapter 2, you can run the provided scripts to get the application going. Chapter 4 goes into the details of what these scripts actually do.

NOTE

If you're using SQL Server authentication, many of these scripts prompt you for the SQL password of the development account you set up in Chapter 2.

  1. Open a Notification Services Command Prompt on your development machine and navigate to the Chapter 3 scripts directory by typing the following command:

  2. cd /d C:\SQL-NS\Chapter03\Scripts
  3. Run create.cmd.

  4. Run register.cmd. You will be prompted for the password of the Windows account you created in Chapter 2 for running the SQL-NS engine. (Note that this is the password of the Windows account, not the SQL user you created if you're using SQL Server authentication.) If you're using SQL Server authentication, after entering the password for the Windows account, you will then be prompted for the SQL password of the test account you created in Chapter 2.

  5. Run grant_permissions.cmd. If you're using SQL Server authentication, you will be prompted for the password for your SQL Server's system administrator account.

  6. Run enable.cmd.

  7. Start the SQL-NS engine using the following command. When you completed the register command in step 3, SQL-NS installed a Windows Service that hosts the execution engine for this instance. The service for any instance is always named NS$<InstanceName>, so for this instance, the service is named NS$Chapter03.

  8. net start NS$Chapter03

At this point, the application should be running, and we can start submitting subscriptions and events. If your service does not start correctly, refer to Chapter 15, "Troubleshooting SQL-NS Applications," for suggestions on how to diagnose the problem.

We'll use a pair of VBScripts that use the SQL-NS APIs to enter subscriber and subscription data. I've provided a batch file that invokes these VBScripts with the appropriate arguments. Chapter 7 examines the details of the API that these scripts employ.

  1. Open a Notification Services Command Prompt on your development machine and navigate to the Chapter 3 scripts directory by typing the following command:

  2. cd /d C:\SQL-NS\Chapter03\Scripts
  3. Run add_subscriber_subscriptions.cmd. If you're using SQL Server authentication, you will be prompted for the SQL password of the test account you set up in Chapter 2.

For events, remember that this application uses the built-in FileSystemWatcher event provider, which watches a specific directory for new data files. It has been configured to watch the Stock\EventsWatchDirectory directory, so we'll copy a data file into this folder to kick things off. In the Stock\SampleData directory, a file called EventData.xml contains some sample stock price change events we can use for this purpose (you looked at this file earlier in this chapter).

  1. Open a Notification Services Command Prompt on your development machine and navigate to the sample data directory by typing the following command:

  2. cd /d C:\SQL-NS\Chapter03\Stock\SampleData
  3. Copy the file EventData.xml into the directory being watched for events using the following command:

  4. copy EventData.xml ..\EventsWatchDirectory

If you look at the Stock\EventsWatchDirectory folder, you'll see that after the event provider picks up the file (this should happen within a few seconds of copying the file into the directory), the file gets renamed to eventdata.xml.<timestamp>.done where <timestamp> represents the date and time the file was processed.

The event data in the sample file just submitted is designed to match some of the subscriptions added through the VBScript, so this data should generate notifications. The generation process may take up to a few minutes, because the generator repeatedly looks for new batches of events on a 1-minute interval. (This is, of course, configurable, and Chapter 12 describes how to change this setting.)

This application uses the built-in SQL-NS file delivery protocol, so the notification data will simply be written to a text file. The delivery protocol is configured to write notifications to a file called FileNotifications.txt in the Chapter03\Output\Notifications directory. Within a few minutes, this file should appear in this folder. Open it to see the text of the notifications generated for the sample events and subscriptions just submitted.

  • + Share This
  • 🔖 Save To Your Account