http://msdn.microsoft.com/zh-cn/library/ms160854(v=sql.90).aspx 指令碼樣本 (Reporting Services) SQL Server 2005 此主題尚未評級 - 評價此主題
以下樣本提供了使用 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
修改指令檔
您可以使用文字編輯器開啟所有 .rss 檔案。 請參閱 任務 編譯和運行程式碼範例
SQL Server Reporting Services 樣本
其他資源 Scripting with the rs Utility and the Web Service
應用程式樣本 (Reporting Services)
Accessing the SOAP API
協助和資訊 擷取 SQL Server 2005 協助
=========
'=============================================================================' 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]() = NothingDim warnings As Warning() = NothingDim parentFolder As String = "AdventureWorks Sample Reports"Dim parentPath As String = "/" + parentFolderDim 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 SubPublic 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 = FalseTry 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 TryEnd Sub