天天看點

腳本示例 (Reporting Services)Microsoft Visual Basic .NET腳本示例 (Reporting Services)

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 進行報表伺服器上的大多數管理操作。

腳本示例 (Reporting Services)Microsoft Visual Basic .NET腳本示例 (Reporting Services)
重要提示:
這些示例僅供教學使用。這些不是針對生産環境設計的,也沒有在生産環境中進行測試。對于這些示例,Microsoft 不提供相關的技術支援。

下表對示例腳本進行了說明。

檔案 說明
AddItemSecurity.rss 示範如何使用腳本在報表伺服器命名空間中設定項安全性政策。
CancelRunningJobs.rss 示範一個示例管理腳本,該腳本可取消報表伺服器上運作的作業。
ConfigureSystemProperties.rss 示範一個可以用來設定系統級屬性和報表伺服器屬性的腳本。
PublishSampleReports.rss 示範一個可以将示例報表釋出到報表伺服器的腳本。
腳本示例 (Reporting Services)Microsoft Visual Basic .NET腳本示例 (Reporting Services)

要求

在運作示例腳本之前,必須要滿足以下條件:

  • 必須使用 Reporting Services 安裝程式或單獨的示例安裝程式,先将示例報表和腳本檔案安裝到硬碟上。
  • 您必須擁有在安裝了報表伺服器執行個體的計算機上運作 rs 實用工具的權限。
  • 您必須擁有報表伺服器的通路權限,才能使用腳本對它進行通路。
  • 您必須對要通路的報表伺服器的根檔案夾具有相應的權限。有關權限和使用者角色的詳細資訊,請參閱管理 Reporting Services 的權限和安全性。
腳本示例 (Reporting Services)Microsoft Visual Basic .NET腳本示例 (Reporting Services)

腳本檔案的位置

将示例安裝到預設安裝目錄時,預設情況下,腳本示例位于 C:\Program Files\Microsoft SQL Server\90\Samples\Reporting Services\Script Samples。

腳本示例 (Reporting Services)Microsoft Visual Basic .NET腳本示例 (Reporting Services)
注意:
如果尚未安裝示例,請參閱安裝示例。
腳本示例 (Reporting Services)Microsoft Visual Basic .NET腳本示例 (Reporting Services)

運作示例腳本

您可以在 Reporting Services 腳本環境中運作示例腳本。

腳本示例 (Reporting Services)Microsoft Visual Basic .NET腳本示例 (Reporting Services)

運作此示例

  1. Open a command prompt: On the Start menu, click Run, type cmd in the text box, and then click OK.
  2. 導航到包含示例腳本的目錄。例如,如果示例腳本安裝在預設目錄中,請在指令提示符下鍵入以下内容:

    複制

    cd C:\Program Files\Microsoft SQL Server\90\Samples\Reporting Services\Script Samples
          
  3. 在指令提示符下,輸入以下内容,以檢視 rs 實用工具的可用指令提示選項清單:

    複制

    rs -?
          
    腳本示例 (Reporting Services)Microsoft Visual Basic .NET腳本示例 (Reporting Services)
    注意:
    如果收到消息,通知您 rs 不是已知指令或批處理檔案,則需要将 rs.exe 的位置添加到 Windows 環境變量 PATH 中。
  4. 在指令提示符下,鍵入相應的指令以運作該示例腳本檔案。例如,将給定的伺服器 URL 替換為所通路的報表伺服器時,若要運作 PublishSampleReports.rss,請鍵入以下指令:

    複制

    rs -i PublishSampleReports.rss -s http://myserver/reportserver
          
腳本示例 (Reporting Services)Microsoft Visual Basic .NET腳本示例 (Reporting Services)

修改腳本檔案

您可以使用文本編輯器打開所有 .rss 檔案。

腳本示例 (Reporting Services)Microsoft Visual Basic .NET腳本示例 (Reporting Services)

請參閱

任務

編譯和運作代碼示例

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 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 
      

繼續閱讀