脚本示例 (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 进行报表服务器上的大多数管理操作。

ms160854.note(zh-cn,SQL.90).gif重要提示:
这些示例仅供教学使用。这些不是针对生产环境设计的,也没有在生产环境中进行测试。对于这些示例,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。

ms160854.note(zh-cn,SQL.90).gif注意:
如果尚未安装示例,请参阅安装示例

您可以在 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 -?
    
    ms160854.note(zh-cn,SQL.90).gif注意:
    如果收到消息,通知您 rs 不是已知命令或批处理文件,则需要将 rs.exe 的位置添加到 Windows 环境变量 PATH 中。

  4. 在命令提示符下,键入相应的命令以运行该示例脚本文件。例如,将给定的服务器 URL 替换为所访问的报表服务器时,若要运行 PublishSampleReports.rss,请键入以下命令:

    rs -i PublishSampleReports.rss -s http://myserver/reportserver
    

您可以使用文本编辑器打开所有 .rss 文件。

 

=========

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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值