Tech Note 573 Using SQL Server Agent to Run Scheduled Reports All Tech Notes, Tech Alerts and KBCD documents and software are provided "as is" without warranty of any kind. See the Terms of Use for more information. Topic#: 002326 C reated: February 2009 Introduction This Tech Note provides an example of configuring SQL Server Agent to manage the execution of published reports for ActiveFactory. It also provides an example of configuring a custom event Archiving Rule and Scheduled Report Path for the SQL Server Agent. Application Versions Wonderware ActiveFactory 9.2 Wonderware Information Server (WIS) 3.0 Microsoft SQL Server 2005 Configure Event Group To allow SQL Server Agent to trigger when a report is executed, we need to provide a set of report group types. Scheduled Report paths and Archiving rules are configured in the Configuration.config file located at C:\Inetpub\wwwroot\AFWeb. 1. Backup the Configuration.Config file. 2. Open the Configuration.Config file with Notepad. 3. Use the Ctrl+F keys to find the WEEKLY element as it appears in Figure 1 (below). 4. Make a copy of the WEEKLY archival rule element. https://wdnresource.wonderware.com/support/kbcd/html/1/t002326.htm 1/8
FIGURE 1: COPY THE WEEKLY ARCHIVAL RULE 5. Modify the name and description of the new weekly archival rule. In this example, it is called WEEKLYAgent. FIGURE 2: RENAME AFTER COPYING For example: <WEEKLYAgent Description="Rule that applies to all reports assigned to the WEEKLY schedule using sql server agent."> <DIRECTORYNAME> https://wdnresource.wonderware.com/support/kbcd/html/1/t002326.htm 2/8
<FORMATSTRING>MM (MMM)</FORMATSTRING> </DIRECTORYNAME> <FILENAME> <FORMATSTRING>'Week of' dd-mm-yyyy</formatstring> </FILENAME> <OLDERTHAN>365,0,0</OLDERTHAN> <!-- 365 = one year --> <KEEPCOUNT>520</KEEPCOUNT> <!-- 520 = ten years' worth of weekly reports --> </WEEKLYAgent> 5. Create a copy of the Example Report for WEEKLY and name it WEEKLYAgent. You will need this Report Folder Name later. FIGURE 3: WEEKLYAGENT REPORT ELEMENT For example: <WEEKLYAgent> <DIRECTORYNAME> <FORMATSTRING>'Weeks of 'MMM-yyyy</FORMATSTRING> </DIRECTORYNAME> <FILENAME> <FORMATSTRING>'Week of' dd-mm-yyyy</formatstring> </FILENAME> </WEEKLYAgent> 6. Create a copy of the WEEKLY Scheduled Report Path and modify the settings so it mimics the behavior of an Event report type. https://wdnresource.wonderware.com/support/kbcd/html/1/t002326.htm 3/8
FIGURE 4: MODIFIED EVENT REPORT SETTINGS For example: <WEEKLYAgent> <FOLDERNAME>Weekly</FOLDERNAME> <TIMEINTERVAL>0,0,0</TIMEINTERVAL> <!-- Change time interval to Event settings --> <STARTTIME>-1,*,*,*</STARTTIME> <!-- -1 => this never fires on its own --> <DESCRIPTION>Every week (SQL Server Agent)</DESCRIPTION> </WEEKLYAgent> 7. Save the Configuration.Config file. Within 30 seconds, the aahistclientreportingservice rereads this file and identifies the new group. It is then accessible when publishing from ActiveFactory Workbook. If the new Group does not appear, you may have a error in the file. Look at the OS event viewer. Publish the Report 1. Create a new ActiveFactory Workbook report and publish it as a Dynamic report. https://wdnresource.wonderware.com/support/kbcd/html/1/t002326.htm 4/8
FIGURE 5: PUBLISH A DYNAMIC REPORT 2. Select Report Type Scheduled. 3. In the Schedules list, select the new schedule that we created. FIGURE 6: SCHEDULED REPORT TYPE Make sure you remember/save the Report Name as you will need this later. 4. Click OK to publish the report. 5. Report information is stored in the Runtime database on the selected server. The table containing this report is aahistclientreport. If you forget the name of this report, you can view it in this table. It will be needed later. https://wdnresource.wonderware.com/support/kbcd/html/1/t002326.htm 5/8
FIGURE 7: REPORT NAME IN AAHISTCLIENTREPORT TABLE Schedule Report with SQL Server Agent 1. Using Microsoft SQL Server Management Studio, create a new Job for SQL Server Agent. https://wdnresource.wonderware.com/support/kbcd/html/1/t002326.htm 6/8
FIGURE 8: CREATE A NEW SQL SERVER AGENT JOB 2. Provide the General page information for this job. FIGURE 9: GENERAL JOB INFORMATION https://wdnresource.wonderware.com/support/kbcd/html/1/t002326.htm 7/8
3. Select the Steps page and create a new step. Provide the Transact SQL script below. Modify the ReportFolderName and ReportName with the names you have noted in previous steps. UPDATE aahistclientreport SET LastRun='1753-1-1', Published=0 FROM aahistclientreport r, aahistclientreportsfolder f WHERE r.name = 'Book1' AND r.reportfolderkey = f.reportfolderkey AND f.reportfoldername = 'WEEKLYAgent' AND r.reportsitekey = 1 4. Select the Schedules page and create a new schedule. In this example, we created a weekly scheduled report. You can create any schedule you like. Note: The query provided to trigger a report can also be used with the InSQL Event System. Click the following icon to view this file in.pdf format: C. Azer Tech Notes are published occasionally by Wonderware Technical Support. Publisher: Invensys Systems, Inc., 26561 Rancho Parkway South, Lake Forest, C A 92630. There is also technical information on our software products at Wonderware Technical Support. For technical support questions, send an e-mail to support@wonderware.com. Back to top 2013 Invensys Systems, Inc. All rights reserved. No part of the material protected by this copyright may be reproduced or utilized in any form or by any means, electronic or mechanical, including photocopying, recording, broadcasting, or by anyinformation storage and retrieval system, without permission in writing from Invensys Systems, Inc. Terms of Use. https://wdnresource.wonderware.com/support/kbcd/html/1/t002326.htm 8/8