Profit Margin Sample
The Profit Margin sample is an event-driven Microsoft SQL Server Notification Services application that produces notifications about profit margins for individual employees and sends this data to subscribed users. This sample uses the SSAS event provider to query an SSAS database and return the results as events to the Notification Services application.
Note
You cannot run this sample on Itanium-based servers because Business Intelligence Development Studio is not installed.
Scenario
A company has an SSAS database that is used to analyze sales performance. Employees in the Sales department can subscribe to the Profit Margin application to receive a notification when any of their resellers has exceeded their profit margin goal.
On a schedule specified in the application, the SSAS event provider runs an MDX query to gather events. When the generator runs, these events are added to a chronicle. The generator then produces notifications from the event chronicle when the following conditions are met:
- The name of the subscriber matches the name of the employee in the event.
- The reseller's gross profit margin is greater than the reseller's gross profit margin goal.
The resulting notification is formatted by using an XSL transform, and then sent to a file.
Languages
XML, XSD, XSLT, and Microsoft Visual C# or Microsoft Visual Basic.
Features
The SSAS sample uses the following features of Notification Services:
Application Area | Features |
---|---|
Event Class |
Basic event queue and one chronicle. |
Subscription Class |
One event-driven subscription class. |
Notification Class |
One notification class; no digest or multicast delivery. |
Event Providers |
Two SSAS event providers: one static, and one dynamic. |
Content Formatters |
XSLT content formatter. |
Delivery Protocols |
File and SMTP delivery protocols. |
Prerequisites
Before you run this sample, make sure that the following software is installed:
- Microsoft SQL Server 2005, including the following components:
- Database Engine.
- Notification Services.
- SSAS.
- SQL Server Management Studio.
- Business Intelligence Development Studio.
- The AdventureWorksDW database. This database is included with SQL Server 2005, and is also available at the SQL Server Developer Web site. For more information, see Running Setup to Install AdventureWorks Sample Databases and Samples.
- Notification Services samples. These samples are included with SQL Server 2005. You can download the latest version of the samples at the SQL Server Developer Web site.
- .NET Framework SDK 2.0 or Microsoft Visual Studio 2005. You can obtain .NET Framework SDK free of charge. See Installing the .NET Framework SDK.
Building the Sample
To build the sample, you will need to do the following:
- Deploy the SSAS database.
- Create the instance of Notification Services.
- Register the instance of Notification Services.
- Grant SQL Server and database permissions.
The following procedures show how to do each of these tasks for the Profit Margin sample.
Step 1: Deploy the Adventure Works DW OLAP database
Open SQL Server Business Intelligence Development Studio, click File, point to Open, and then click Project/Solution.
Browse to C:\Program Files\Microsoft SQL Server\90\Tools\Samples\AdventureWorks Analysis Services Project, select the Adventure Works DW.dwproj file, and then click Open.
From Solution Explorer, right-click Adventure Works DW and select Deploy.
Step 2: Create the instance of Notification Services
Open SQL Server Management Studio and connect to an instance of SQL Server.
In Object Explorer, right-click the Notification Services folder, and then select New Notification Services Instance.
In the New Notification Services Instance dialog box, click Browse and select the InstanceConfig.xml file in the Profit Margin sample's root folder.
In the Parameters box, enter values for the three parameters:
- SampleDirectory is the path of the Profit Margin sample's root folder. The default path is C:\Program Files\Microsoft SQL Server\90\Samples\Notification Services\ProfitMargin.
- NotificationServicesHost is the local server name.
- SQLServer is the name of the SQL Server instance.
Select the Enable instance after it is created check box.
Click OK..
When Notification Services has finished creating the instance, click Close.
Note
If you are deploying a Notification Services sample using an account that is the database owner or a system administrator, you do not have to grant SQL Server permissions to the account. Granting these permissions might result in an error, which you can ignore. When you deploy your own applications, you should use accounts with lower privileges to help improve security.
Step 3: Register the instance of Notification Services
In SQL Server Management Studio, open the Notification Services node, right-click ProfitMarginInstance, point to Tasks, and then select Register.
In the Register dialog box, select the Create Windows service check box.
The Windows service runs the instance of Notification Services on this computer.
Under Service logon, enter a Windows account and password. This is the Windows account under which the service will run. If you use Windows Authentication to access SQL Server, the Windows service will also use this account to connect to SQL Server.
If you must use SQL Server authentication to access SQL Server, select SQL Server Authentication under Authentication, and then enter a SQL Server login name and password.
We recommend using Windows Authentication.
Click OK..
When Notification Services has finished registering the instance, click Close.
Step 4: Grant SQL Server and database permissions
In Object Explorer, expand the Security node.
If you have to create a new database login account for the Windows service, right-click Logins, select New Login, and then create the Login account:
- To use Windows Authentication, select Windows authentication and enter the same Windows account you specified when registering the instance.
- If you must use SQL Server authentication, select SQL Server authentication, and then enter the same SQL Server login and password that you specified when you registered the instance.
If the login that is used by the Windows service already has access to SQL Server, right-click the login and select Properties.
In the left pane of the Login dialog box, select User Mapping.
Grant permissions for the ProfitMarginInstanceNSMain database:
- In the Users mapped to this login box, select the box that is adjacent to the ProfitMarginInstanceNSMain database.
- In the Database role membership for: ProfitMarginInstanceNSMain box, select NSRunService.
Grant permissions for the ProfitMarginInstanceProfitMargin database:
- In the Users mapped to this login box, select the box that is adjacent to the ProfitMarginInstanceProfitMargin database.
- In the Database role membership for: ProfitMarginInstanceProfitMargin box, select NSRunService.
Click OK to apply SQL Server permissions.
Grant permissions for the Adventure Works DW database:
- In SQL Server Management Studio, connect to SSAS.
- Expand the SSAS Database folder, and then expand Adventure Works DW.
- Right-click Roles and select New Role.
- In the Role name box, enter ProfitMarginNS.
- In the left pane, click Membership and add the account that is used to run this sample's Notification Services Windows service.
- In the left pane, select Cubes.
- For the AdventureWorks Cube, click the Access field and select Read.
- Click OK to apply cube permissions.
Configure security for the Events folder:
- In Windows Explorer, locate the Profit Margin sample's Events folder.
- Right-click the Events folder, select Sharing and Security, and then select the Security tab.
- Click Add and add the account that is used by the Windows service.
- In the Group or user names box, select the account that you just added.
- In the Permissions for box, select the Read and Modify permissions.
- Click OK to apply the changes.
Configure security for the Notifications folder:
- Locate the Profit Margin sample's Notifications folder.
- Right-click the Notifications folder, select Sharing and Security, and then click the Security tab.
- Click Add and add the account that is used by the Windows service.
- In the Group or user names box, select the account that you just added.
- In the Permissions for box, select Write.
- Click OK to apply the changes.
Generating a Strong Name Key File
If you have not already created a strong name key file, generate the key file using the following instructions.
To generate a strong name key file
Open a Microsoft Visual Studio 2005 command prompt. Click Start, point to All Programs, point to Microsoft .NET Framework SDK 2.0, and then click SDK Command Prompt.
-- or --
Open a Microsoft .NET Framework command prompt. Click Start, point to All Programs, point to Microsoft .NET Framework SDK 2.0, and then click SDK Command Prompt.
Use the change directory command (CD) to change the current directory of the command prompt window to the folder where the samples are installed.
Note
To determine the folder where samples are located, click the Start button, point to All Programs, point to Microsoft SQL Server, point to Documentation and Tutorials, and then click Samples Directory. If the default installation location was used, the samples are located in <system_drive>:\Program Files\Microsoft SQL Server\100\Samples.
At the command prompt, run the following command to generate the key file:
sn -k SampleKey.snk
Important
For more information about the strong-name key pair, see "Security Briefs: Strong Names and Security in the .NET Framework" in the .NET Development Center on MSDN.
Running the Sample
To run the sample, do the following:
- Start the instance.
- Add subscribers and subscriptions.
- Add an event to the SSAS data warehouse.
The following procedures show how to perform these tasks and how to view the resulting notifications.
Step 1: Start the instance
In Object Explorer, open the Notification Services folder.
Right-click ProfitMarginInstance, and then click Start.
Step 2: Add subscribers and subscriptions
Build the ProfitMargin or ProfitMargin_VB Visual Studio Solution
If you are using the.NET Framework SDK, do the following:
- On the Start menu, point to All Programs\Microsoft .NET Framework SDK v2.0, and then click SDK Command Prompt.
- Locate the Profit Margin's sample's root folder. Type the following command for the default location:
cd \Program Files\Microsoft SQL Server\90\Samples\Notification Services\ProfitMargin - Type the following to build the solution
[C#]
msbuild ProfitMargin.sln
[Visual Basic]
msbuild ProfitMargin_VB.sln
If you are using Visual Studio 2005, do the following:
- Open the solution file of your choice (ProfitMargin.sln or ProfitMargin_VB.sln).
- Press F6 to build the solution.
Run AddSubscribers.exe.
The default location for this file is C:\Program Files\Microsoft SQL Server\90\Samples\Notification Services\ProfitMargin\AddSubscribers\language\AddSubscribers\bin\Debug.
Run AddSubscriptions.exe.
C:\Program Files\Microsoft SQL Server\90\Samples\Notification Services\ProfitMargin\AddSubscriptions\language\AddSubscriptions\bin\Debug.
Note
For production applications, or if you are running this application under a restricted account, add the application's SQL Server login to the NSSubscriberAdmin database role in the instance and application databases.
Step 3: Add an event to the Analysis Services data warehouse
Open a New SQL Server Query window in SQL Server Management Studio.
Open the TriggerEvent.sql file in the ProfitMargin/SQL Scripts folder to add data to the AdventureWorks data warehouse. This data will generate an event.
Note
If you run this script again, you must change the SalesOrderNumber by changing the SELECT @SalesOrderNumber character value to add a new sales order.
Reprocess the cube:
- In SQL Server Management Studio Object Explorer, click Connect, and then select Analysis Server.
- In the Connect to Server dialog box, type the server name that hosts the AdventureWorksDW cube in the Server name box, and then click Connect.
- In Object Explorer, open the Analysis Server node, open the Databases folder, and then locate Adventure Works DW/Cubes/Adventure Works/Measure Groups/Reseller Sales.
- Right-click Reseller Sales, and then select Process.
- Click OK to reprocess the Reseller Sales cube.
Step 4: View notifications
Give Notification Services approximately one minute to produce notifications.
In Windows Explorer, locate the Profit Margin sample's Notifications folder. You should find a file named FileNotifications.txt. This file contains the notifications.
Locate the folder where e-mail messages are dropped. This is typically in one of the folders in C:\Inetpub\mailroot. Depending on the SMTP server state, the notifications should be in either the Pickup folder or Queue folder. If the SMTP service is running, the messages might be moved to the Badmail folder.
Removing the Sample
Use the following procedure to remove the Profit Margin sample.
To remove the ProfitMargin sample
In the Object Explorer pane, open the Notification Services folder.
Right-click ProfitMarginInstance, and then select Stop.
Right-click ProfitMarginInstance, point to Tasks, and then select Unregister.
Right-click ProfitMarginInstance, point to Tasks, and then select Delete.
See Also
Other Resources
SQL Server Notification Services Samples
Securing Notification Services
Help and Information
Getting SQL Server 2005 Assistance
Change History
Release | History |
---|---|
14 April 2006 |
|
5 December 2005 |
|