Summary


When you first build a new SQL-NS application, you may well have errors in the application logic specified in the ADF. Syntax errors are usually easy to find and fix because they typically show up at compile time. Semantic errors, on the other hand, are usually more problematic because, in most cases, they manifest themselves only through unexpected results at runtime. To track down semantic errors, it usually helps to run the application's rules manually, examine the state of the application at several intermediate stages, and run test queries to isolate problems.

Unfortunately, you cannot take rule text out of the ADF and run it directly against the database. Rules rely on runtime state set up by the generator at the time the rule is run; without this state in place, the rule execution will fail or produce unpredictable results. To run rules manually, SQL-NS provides a set of debugging stored procedures you can use to mimic the runtime state set up by the generator. Using these stored procedures, you can execute rules outside the generator, examine their inputs and outputs, and look at the intermediate state of the application between individual rule executions.

Before exploring the details of the debugging stored procedures, we looked at internals of the notification generator to understand the runtime environment in which it executes rules. The generator works off a quantum clock that divides continuous time into discrete, fixed-length quantums. Quantums scope the data that the generator sees at any given time. When processing a particular quantum, event rules execute only against event batches submitted during that quantum, and scheduled rules execute only against those subscriptions due to be evaluated during that quantum. In the processing of a quantum, the generator performs several operations: It selects events and subscriptions against which the rules will run, sets up views of the event and subscription data, executes rules, and then cleans up.

After looking at the generator internals, we used the debugging stored procedures to manually execute rules in the music store application. We disabled the generator, submitted an event batch, and then used the NSSetQuantumClock stored procedure to set the quantum clock to the time period in which the event batch was submitted. We then used the NSPrepareRuleFiring stored procedure to set up the runtime state for rule execution and used the NSExecuteRuleFiring stored procedure to invoke each rule. Finally, we looked at the NSScheduledSubscriptionDetails and NSScheduledSubscriptionList stored procedures that evaluate subscription schedules and determine which scheduled subscriptions will be evaluated during a given time period.

There weren't any problems with the music store application that needed to be debugged, but the debugging techniques we applied in this chapter can easily be used in other applications. These techniques will help you track down problems with your applications and get your prototype running quickly.




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