脚本示例 (Reporting Services)Microsoft Visual Basic .NET
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]() = 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 folderTryrs.CreateFolder(parentFolder, "/", Nothing)Console.WriteLine("Parent folder {0} created successfully", parentFolder)Catch e As ExceptionConsole.WriteLine(e.Message)End Try'Create the AdventureWorks shared data sourceCreateSampleDataSource("AdventureWorks", "SQL", "data source=(local);initial catalog=AdventureWorks")CreateSampleDataSource("AdventureWorksDW", "OLEDB-MD", _"data source=localhost;initial catalog=Adventure Works DW")'Publish the sample reportsPublishReport("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.Integrateddefinition.ConnectString = connectionStringdefinition.Enabled = Truedefinition.EnabledSpecified = Truedefinition.Extension = extensiondefinition.ImpersonateUser = Falsedefinition.ImpersonateUserSpecified = True'Use the default prompt string.definition.Prompt = Nothingdefinition.WindowsCredentials = FalseTryrs.CreateDataSource(name, parentPath, False, definition, Nothing)Console.WriteLine("Data source {0} created successfully", name)Catch e As ExceptionConsole.WriteLine(e.Message) End TryEnd Sub Public Sub PublishReport(ByVal reportName As String)TryDim 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 IOExceptionConsole.WriteLine(e.Message)End TryTrywarnings = rs.CreateReport(reportName, parentPath, False, definition, Nothing)If Not (warnings Is Nothing) ThenDim warning As WarningFor Each warning In warningsConsole.WriteLine(warning.Message)Next warningElseConsole.WriteLine("Report: {0} published successfully with no warnings", reportName)End IfCatch e As ExceptionConsole.WriteLine(e.Message)End Try End Sub?
總結
以上是生活随笔為你收集整理的脚本示例 (Reporting Services)Microsoft Visual Basic .NET的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: rs 实用工具 (rs.exe) (SS
- 下一篇: asp.net ajax控件工具集 Au