http://msdn.microsoft.com/zh-cn/library/ms160854(v=sql.90).aspx
脚本示例 (Reporting Services)
以下示例提供了使用 Microsoft Visual Basic .NET 为 Reporting Services 编写的脚本。脚本示例通常是针对单个功能或技术问题的,是基于任务的。您可以使用脚本文件和 Reporting Services SOAP API 进行报表服务器上的大多数管理操作。
![]() |
---|
这些示例仅供教学使用。这些不是针对生产环境设计的,也没有在生产环境中进行测试。对于这些示例,Microsoft 不提供相关的技术支持。 |
下表对示例脚本进行了说明。
文件 | 说明 |
---|---|
AddItemSecurity.rss | 示范如何使用脚本在报表服务器命名空间中设置项安全性策略。 |
CancelRunningJobs.rss | 示范一个示例管理脚本,该脚本可取消报表服务器上运行的作业。 |
ConfigureSystemProperties.rss | 示范一个可以用来设置系统级属性和报表服务器属性的脚本。 |
PublishSampleReports.rss | 示范一个可以将示例报表发布到报表服务器的脚本。 |
在运行示例脚本之前,必须要满足以下条件:
- 必须使用 Reporting Services 安装程序或单独的示例安装程序,先将示例报表和脚本文件安装到硬盘上。
- 您必须拥有在安装了报表服务器实例的计算机上运行 rs 实用工具的权限。
- 您必须拥有报表服务器的访问权限,才能使用脚本对它进行访问。
- 您必须对要访问的报表服务器的根文件夹具有相应的权限。有关权限和用户角色的详细信息,请参阅管理 Reporting Services 的权限和安全性。
将示例安装到默认安装目录时,默认情况下,脚本示例位于 C:\Program Files\Microsoft SQL Server\90\Samples\Reporting Services\Script Samples。
![]() |
---|
如果尚未安装示例,请参阅安装示例。 |
您可以在 Reporting Services 脚本环境中运行示例脚本。
-
Open a command prompt: On the Start menu, click Run, type cmd in the text box, and then click OK.
-
导航到包含示例脚本的目录。例如,如果示例脚本安装在默认目录中,请在命令提示符下键入以下内容:
cd C:\Program Files\Microsoft SQL Server\90\Samples\Reporting Services\Script Samples
-
在命令提示符下,输入以下内容,以查看 rs 实用工具的可用命令提示选项列表:
rs -?
注意:
如果收到消息,通知您 rs 不是已知命令或批处理文件,则需要将 rs.exe 的位置添加到 Windows 环境变量 PATH 中。 -
在命令提示符下,键入相应的命令以运行该示例脚本文件。例如,将给定的服务器 URL 替换为所访问的报表服务器时,若要运行 PublishSampleReports.rss,请键入以下命令:
rs -i PublishSampleReports.rss -s http://myserver/reportserver
=========
'============================================================================= ' File: PublishSampleReports.rss ' ' Summary: Demonstrates a script that can be used with RS.exe to ' publish the sample reports that ship with Reporting Services. ' '--------------------------------------------------------------------- ' This file is part of Microsoft SQL Server Code Samples. ' ' Copyright (C) Microsoft Corporation. All rights reserved. ' ' This source code is intended only as a supplement to Microsoft ' Development Tools and/or on-line documentation. See these other ' materials for detailed information regarding Microsoft code samples. ' ' THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY ' KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE ' IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A ' PARTICULAR PURPOSE. '============================================================================= ' ' 1.0 Documentation ' ' Read the following in order to familiarize yourself with the sample script. ' ' 1.1 Overview ' ' This sample script uses a script file (.rss) and the script environment to run ' Web service operations on a specified report server. The script creates a folder ' that you specify as a command-prompt variable using the 杤 switch, and then ' publishes the sample reports that ship with Reporting Services to a report server. ' Depending on the location of your sample reports, you may need to modify the ' value of the filePath variable, which references the path to your sample reports. ' ' 1.2 Script Variables ' ' Variables that are passed on the command line with the -v switch: ' ' (a) parentFolder - corresponds to the folder that the script creates and uses ' to contain your published reports ' ' 1.3 Sample Command Lines ' ' ' 1.3.1 Use the script to publish the sample reports to an AdventureWorks Sample Reports folder. ' ' rs -i PublishSampleReports.rss -s http://myserver/reportserver ' Dim definition As [Byte]() = Nothing Dim warnings As Warning() = Nothing Dim parentFolder As String = "AdventureWorks Sample Reports" Dim parentPath As String = "/" + parentFolder Dim filePath As String = "C:\Program Files\Microsoft SQL Server\100\Samples\Reporting Services\Report Samples\AdventureWorks Sample Reports\" Public Sub Main() rs.Credentials = System.Net.CredentialCache.DefaultCredentials 'Create the parent folder Try rs.CreateFolder(parentFolder, "/", Nothing) Console.WriteLine("Parent folder {0} created successfully", parentFolder) Catch e As Exception Console.WriteLine(e.Message) End Try 'Create the AdventureWorks shared data source CreateSampleDataSource("AdventureWorks", "SQL", "data source=(local);initial catalog=AdventureWorks") CreateSampleDataSource("AdventureWorksDW", "OLEDB-MD", _ "data source=localhost;initial catalog=Adventure Works DW") 'Publish the sample reports PublishReport("Company Sales") PublishReport("Employee Sales Summary") PublishReport("Product Catalog") PublishReport("Product Line Sales") PublishReport("Sales Order Detail") PublishReport("Territory Sales Drilldown") End Sub Public Sub CreateSampleDataSource(name As String, extension As String, connectionString As String) 'Define the data source definition. Dim definition As New DataSourceDefinition() definition.CredentialRetrieval = CredentialRetrievalEnum.Integrated definition.ConnectString = connectionString definition.Enabled = True definition.EnabledSpecified = True definition.Extension = extension definition.ImpersonateUser = False definition.ImpersonateUserSpecified = True 'Use the default prompt string. definition.Prompt = Nothing definition.WindowsCredentials = False Try rs.CreateDataSource(name, parentPath, False, definition, Nothing) Console.WriteLine("Data source {0} created successfully", name) Catch e As Exception Console.WriteLine(e.Message) End Try End Sub Public Sub PublishReport(ByVal reportName As String) Try Dim stream As FileStream = File.OpenRead(filePath + reportName + ".rdl") definition = New [Byte](stream.Length) {} stream.Read(definition, 0, CInt(stream.Length)) stream.Close() Catch e As IOException Console.WriteLine(e.Message) End Try Try warnings = rs.CreateReport(reportName, parentPath, False, definition, Nothing) If Not (warnings Is Nothing) Then Dim warning As Warning For Each warning In warnings Console.WriteLine(warning.Message) Next warning Else Console.WriteLine("Report: {0} published successfully with no warnings", reportName) End If Catch e As Exception Console.WriteLine(e.Message) End Try End Sub