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 complete the steps described here to get the application going. In this chapter, I've just listed the steps without explaining the purpose of each one in detail. Chapter 4 goes into the details of what these steps actually do.

1.

If you have not already done so, open the C:\SQL-NS\Samples\StockBroker\StockBroker.ssmssln solution in Management Studio.

2.

If the Object Explorer pane is not visible, open it by selecting Object Explorer from the View menu, or by pressing F8.

3.

In the Object Explorer, connect to the SQL Server you plan to use for SQL-NS development. To do this, click the Connect button, choose Database Engine from the drop-down list, enter the connection information in the dialog box that appears, and finally, click Connect. If you're using SQL Server Authentication, make sure you connect using the credentials of your development account.

4.

In the Object Explorer tree, find the Notification Services folder. It should be empty, unless any SQL-NS instances already exist on the SQL Server.

5.

Right-click the Notification Services folder and select New Notification Services Instance.

6.

In the New Notification Services Instance dialog box, click the Browse button to browse for the stock instance's ICF. In the File Open dialog box, navigate to C:\SQL-NS\Samples\StockBroker and select the InstanceConfiguration.xml file.

Caution

If the C:\SQL-NS\Samples\StockBroker\InstanceConfiguration.xml file appears to be missing on your system, you probably have not completed all the setup steps given in Chapter 2. If this is the case, return to Chapter 2 and make sure you complete the steps in the "Customizing the Source Files for Your Environment" section (p. 39).

7.

The Parameters grid in the New Notification Services Instance dialog box will be populated with the parameters from the ICF. You should not have to change any of these values.

8.

Check the box labeled Enable Instance After It Is Created, below the Parameters grid.

9.

Click the OK button to begin compiling the instance and its associated application. A progress dialog box will appear, listing the various steps being performed. When all steps are complete, you should see the status reported as Success. When this happens, click Close to dismiss the progress dialog box.

10.

Now you should see a new item in the Notification Services folder in the Object Explorer tree: an instance named StockBroker.

11.

Right-click this new instance and select Tasks, and then select Register from the context menus. The Register Instance dialog box opens.

12.

Check the box labeled Create Windows Service.

13.

Beneath the Service Logon label, enter the name and password for the Windows user account you created in Chapter 2 to run the SQL-NS service. If your service user account is a domain account, don't forget to qualify the account name with the domain name.

14.

If you're using SQL Server Authentication, select the option button labeled SQL Server Authentication beneath the Authentication label. Enter the SQL login name and password for the test account you created in Chapter 2. If you're using Windows Authentication, leave the Windows Authentication option button selected.

15.

Click OK to begin registering the instance. A progress dialog box listing the various registration operations will appear. When registration completes successfully, click the Close button to dismiss the progress dialog box.

16.

In the Solution Explorer, expand the Queries folder under the StockBroker project and open the SQLPermissions.sql file. Execute the code in this file by pressing F5. This grants the SQL-NS service permission to access the application's database.

17.

Right-click the StockBroker instance in the Object Explorer and select Start from the context menu. Click Yes in the confirmation dialog box to proceed with starting the SQL-NS service for the instance.

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.

To add subscribers, subscriptions, and events, we'll use the T-SQL test script you examined earlier:

1.

Open the Test.sql file in Management Studio. The file is located under the Queries folder in the StockBroker project.

2.

Before you run Test.sql, open the FileNotifications.txt file from the Miscellaneous folder under the StockBroker project in the Solution Explorer. This is the output file to which the notifications will be written when events are matched against subscriptions. When you first open it, the file should be blank.

3.

Go back to Test.sql and execute its contents by pressing F5.

Caution

If the Test.sql script reports error messages saying that it failed to add subscribers because subscription management is disabled for the instance, you probably forgot to check the Enable Instance After It Is Created check box in step 8 of the earlier instructions. If you see these error messages, right-click the StockBroker instance in the Object Explorer and select Enable from the context menu. Click Yes in the confirmation dialog box and then rerun Test.sql.

After Test.sql completes, the SQL-NS engine begins processing the events and subscriptions by executing the matching logic query defined in the ADF. The distributor in the SQL-NS engine picks up the rows of data that result from the matching query, formats them, and then writes the formatted messages out to the notifications file. Within about a minute, Management Studio should pop up a dialog box telling you that the FileNotifications.txt file has changed and asking you if you want to reload it. Click Yes to reload the file and you will see the contents of the notifications that were generated.

The particular event and subscription data submitted by the Test.sql script was chosen to generate some matches. If you go back and look at the data values in Test.sql, you'll easily see which events and subscriptions satisfy the matching criteria defined by the query in the ADF. The contents of the FileNotifications.txt file should reflect these matches.

Feel free to edit Test.sql and enter some new events and subscriptions with different values. If you do this, be certain that you don't rerun the statements that enter subscriber and subscriber device records: SQL-NS does not allow duplicate subscribers or subscriber devices, so these statements should be run only once. After you submit new events and subscriptions, any matches that occur will result in new notification messages written to FileNotifications.txt.




Microsoft SQL Server 2005 Notification Services
Microsoft SQL Server 2005 Notification Services
ISBN: 0672327791
EAN: 2147483647
Year: 2006
Pages: 166
Authors: Shyam Pather

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net