SQL Server Reporting Service 报表 - 命令行部署脚本介绍
2009-02-20 10:22:33 来源:WEB开发网其实看上去也不难, 其中重点介绍一个参数, 大家可以看到-i这个参数中需要传输一个脚本文件给该工具, 其实这个脚本文件也是一般的VB.NET语法写的, 在网上查了一些资料, SQL Server 安装包中没有默认包含脚本实例, 所以我们需要自己下载一下, 大家可以通过: http://www.codeplex.com/MSFTRSProdSamples 这个网站下载并安装, 其中会下载到一个安装包, 它包含了所有 SQL Server 中技术的实例, 安装完成后, 我们进入C:Program FilesMicrosoft SQL Server90SamplesReporting Services 目录, 然后找到一个名为 "Script Samples" 的目录, 这个目录中有若干个RSS为后缀的文件, 这些文件就是脚本文件里, 打开一个名为PublishSampleReports.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 FilesMicrosoft SQL Server90SamplesReporting ServicesReport SamplesAdventureWorks Sample Reports"
Public Sub Main()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()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()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
除了一些专有的rs链接服务器的操作, 大部分代码还是很清晰的, 而且发布数据源和报表都单独列为一个方法, 我们只要摘取其中的内容, 建立我们的新报表就可以完成一个可用的发布报表的脚本了, 这里我不写了, 如果懒得下载的朋友直接使用上面的代码也是一样的.
然后使用:
RS -i "PublishReports.rss" -s "http://[ReportServer]/ReportServer/"
命令就可以执行报表部署操作了.
介绍就到这里, 我将在近期发布一篇关于TFS和报表服务技巧的文章, 其中会具体给大家一个实例代码, 敬请期待! 感谢!
- ››sql server自动生成批量执行SQL脚本的批处理
- ››sql server 2008亿万数据性能优化
- ››SQL Server 2008清空数据库日志方法
- ››sqlserver安装和简单的使用
- ››SQL Sever 2008 R2 数据库管理
- ››SQL SERVER无法安装成功,sqlstp.log文件提示[未发...
- ››Sql Server中通过父记录查找出所有关联的子记录
- ››SqlServer触发器、存储过程和函数
- ››SQL Server 中的事务(含义,属性,管理)
- ››Sqlite数据库插入和读取图片数据
- ››Sql server 2005拒绝了对对象 'xx表' (数...
- ››Sql server 2005拒绝了对对象 'xx表' (数...
更多精彩
赞助商链接