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.
If you have not already done so, open the C:\SQL-NS\Samples\StockBroker\StockBroker.ssmssln solution in Management Studio.
If the Object Explorer pane is not visible, open it by selecting Object Explorer from the View menu, or by pressing F8.
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.
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.
Right-click the Notification Services folder and select New Notification Services Instance.
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.
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.
Check the box labeled Enable Instance After It Is Created, below the Parameters grid.
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.
Now you should see a new item in the Notification Services folder in the Object Explorer tree: an instance named StockBroker.
Right-click this new instance and select Tasks, and then select Register from the context menus. The Register Instance dialog box opens.
Check the box labeled Create Windows Service.
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.
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.
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.
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.
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:
- Open the Test.sql file in Management Studio. The file is located under the Queries folder in the StockBroker project.
- 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.
- Go back to Test.sql and execute its contents by pressing F5.
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.