SQL Server Reporting Service - Deployment by command line

Chinese version: http://www.cnblogs.com/WilsonWu/archive/2009/02/19/1394198.html

Some times when we use the SQL Server Reporting Service will get the same problem, if we have a product constituted by some reports, and there is a new release will be published, we want to get a better way instead of give are RDL files to users directly. actually, SQL Server Reporting already has a tool named RS.exe to help us do some works such as deployment by command line. and today I will introduce main functions in this RS.exe tool:

At first, we use –? to get help information like below:

SQL Server Reporting Service - Deployment by command lineD:\RS>rs -? 
SQL Server Reporting Service - Deployment by command lineMicrosoft 
(R) Reporting Services RS 
SQL Server Reporting Service - Deployment by command lineVersion 
10.0.1600.22 ((SQL_PreRelease).080709-1414 ) x86 
SQL Server Reporting Service - Deployment by command lineExecutes script file contents against the specified Report Server
. 
SQL Server Reporting Service - Deployment by command lineRS -i inputfile -s serverURL [-u username] [-p password] 
SQL Server Reporting Service - Deployment by command line   [-l timeout] [-b] [-e endpoint] [-v var
=value] [-t] 
SQL Server Reporting Service - Deployment by command line
SQL Server Reporting Service - Deployment by command line        -i  inputfile   Script file to execute 
SQL Server Reporting Service - Deployment by command line        -s  serverURL   URL 
(including server and vroot) to execute 
SQL Server Reporting Service - Deployment by command line                        script against
. 
SQL Server Reporting Service - Deployment by command line        -u  username    User name used to log in to the server
. 
SQL Server Reporting Service - Deployment by command line        -p  password    Password used to log in to the server
. 
SQL Server Reporting Service - Deployment by command line        -e  endpoint    Web service endpoint to 
use with the script. 
SQL Server Reporting Service - Deployment by command line                        Options are: 
SQL Server Reporting Service - Deployment by command line                        Exec2005 - The ReportExecution2005 endpoint 
SQL Server Reporting Service - Deployment by command line                        Mgmt2005 - The ReportService2005 endpoint 
SQL Server Reporting Service - Deployment by command line        -l  timeout     Number of seconds before the connection to the 
SQL Server Reporting Service - Deployment by command line                        server times out
. Default is 60 seconds and 0 is 
SQL Server Reporting Service - Deployment by command line                        infinite 
time out. 
SQL Server Reporting Service - Deployment by command line        -b              
Run as a batch and rollback if commands fail 
SQL Server Reporting Service - Deployment by command line        -v  var
=value   Variables and values to pass to the script 
SQL Server Reporting Service - Deployment by command line        -t  
trace       Include trace information in error message

 

In fact, that is not hard to understand, only the “-i” parameter maybe has some questions, all right, the “-i” parameter need a script that can run some code to do our work, the script can be wrote by VS.NET, and I have got some information for the script here. at first you must go to the http://www.codeplex.com/MSFTRSProdSamples site to get a sample package, and this have not include into SQL Server install package. after install it go to your SQL Server location like C:\Program Files\Microsoft SQL Server\90\Samples\Reporting Services, you can see a folder named “Script Samples”, then open it and find the “PublishSampleReports.rss” file like below:

 

SQL Server Reporting Service - Deployment by command line'============================================================================= 
SQL Server Reporting Service - Deployment by command line'
  File:      PublishSampleReports.rss 
SQL Server Reporting Service - Deployment by command line'
 
SQL Server Reporting Service - Deployment by command line'
  Summary:  Demonstrates a script that can be used with RS.exe to 
SQL Server Reporting Service - Deployment by command line'
         publish the sample reports that ship with Reporting Services. 
SQL Server Reporting Service - Deployment by command line'
 
SQL Server Reporting Service - Deployment by command line'
--------------------------------------------------------------------- 
SQL Server Reporting Service - Deployment by command line'
 This file is part of Microsoft SQL Server Code Samples. 
SQL Server Reporting Service - Deployment by command line'
 
SQL Server Reporting Service - Deployment by command line'
  Copyright (C) Microsoft Corporation.  All rights reserved. 
SQL Server Reporting Service - Deployment by command line'
 
SQL Server Reporting Service - Deployment by command line'
 This source code is intended only as a supplement to Microsoft 
SQL Server Reporting Service - Deployment by command line'
 Development Tools and/or on-line documentation.  See these other 
SQL Server Reporting Service - Deployment by command line'
 materials for detailed information regarding Microsoft code samples. 
SQL Server Reporting Service - Deployment by command line'
 
SQL Server Reporting Service - Deployment by command line'
 THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
SQL Server Reporting Service - Deployment by command line'
 KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 
SQL Server Reporting Service - Deployment by command line'
 IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 
SQL Server Reporting Service - Deployment by command line'
 PARTICULAR PURPOSE. 
SQL Server Reporting Service - Deployment by command line'
============================================================================= 
SQL Server Reporting Service - Deployment by command line'
 
SQL Server Reporting Service - Deployment by command line'
 1.0 Documentation 
SQL Server Reporting Service - Deployment by command line'
 
SQL Server Reporting Service - Deployment by command line'
 Read the following in order to familiarize yourself with the sample script. 
SQL Server Reporting Service - Deployment by command line'
 
SQL Server Reporting Service - Deployment by command line'
 1.1 Overview 
SQL Server Reporting Service - Deployment by command line'
 
SQL Server Reporting Service - Deployment by command line'
 This sample script uses a script file (.rss) and the script environment to run 
SQL Server Reporting Service - Deployment by command line'
 Web service operations on a specified report server. The script creates a folder 
SQL Server Reporting Service - Deployment by command line'
 that you specify as a command-prompt variable using the 杤 switch, and then 
SQL Server Reporting Service - Deployment by command line'
 publishes the sample reports that ship with Reporting Services to a report server. 
SQL Server Reporting Service - Deployment by command line'
 Depending on the location of your sample reports, you may need to modify the 
SQL Server Reporting Service - Deployment by command line'
 value of the filePath variable, which references the path to your sample reports. 
SQL Server Reporting Service - Deployment by command line'
 
SQL Server Reporting Service - Deployment by command line'
 1.2 Script Variables 
SQL Server Reporting Service - Deployment by command line'
 
SQL Server Reporting Service - Deployment by command line'
 Variables that are passed on the command line with the -v switch: 
SQL Server Reporting Service - Deployment by command line'
 
SQL Server Reporting Service - Deployment by command line'
 (a) parentFolder - corresponds to the folder that the script creates and uses 
SQL Server Reporting Service - Deployment by command line'
     to contain your published reports 
SQL Server Reporting Service - Deployment by command line'
 
SQL Server Reporting Service - Deployment by command line'
 1.3 Sample Command Lines 
SQL Server Reporting Service - Deployment by command line'
 
SQL Server Reporting Service - Deployment by command line'
 
SQL Server Reporting Service - Deployment by command line'
 1.3.1 Use the script to publish the sample reports to an AdventureWorks Sample Reports folder. 
SQL Server Reporting Service - Deployment by command line'
 
SQL Server Reporting Service - Deployment by command line'
       rs -i PublishSampleReports.rss -s http://myserver/reportserver 
SQL Server Reporting Service - Deployment by command line'
 
SQL Server Reporting Service - Deployment by command line

SQL Server Reporting Service - Deployment by command line
Dim definition As [Byte]() = Nothing 
SQL Server Reporting Service - Deployment by command line
Dim warnings As Warning() = Nothing 
SQL Server Reporting Service - Deployment by command line
Dim parentFolder As String = "AdventureWorks Sample Reports" 
SQL Server Reporting Service - Deployment by command line
Dim parentPath As String = "/" + parentFolder 
SQL Server Reporting Service - Deployment by command line
Dim filePath As String = "C:\Program Files\Microsoft SQL Server\90\Samples\Reporting Services\Report Samples\AdventureWorks Sample Reports\" 
SQL Server Reporting Service - Deployment by command line
SQL Server Reporting Service - Deployment by command lineSQL Server Reporting Service - Deployment by command line
Public Sub Main()Sub Main() 
SQL Server Reporting Service - Deployment by command line
SQL Server Reporting Service - Deployment by command line    rs.Credentials 
= System.Net.CredentialCache.DefaultCredentials 
SQL Server Reporting Service - Deployment by command line    
'Create the parent folder 
SQL Server Reporting Service - Deployment by command line
    Try 
SQL Server Reporting Service - Deployment by command line        rs.CreateFolder(parentFolder, 
"/"Nothing
SQL Server Reporting Service - Deployment by command line        Console.WriteLine(
"Parent folder {0} created successfully", parentFolder) 
SQL Server Reporting Service - Deployment by command line    
Catch e As Exception 
SQL Server Reporting Service - Deployment by command line        Console.WriteLine(e.Message) 
SQL Server Reporting Service - Deployment by command line    
End Try 
SQL Server Reporting Service - Deployment by command line
SQL Server Reporting Service - Deployment by command line    
'Create the AdventureWorks shared data source 
SQL Server Reporting Service - Deployment by command line
    CreateSampleDataSource("AdventureWorks""SQL""data source=(local);initial catalog=AdventureWorks"
SQL Server Reporting Service - Deployment by command line    CreateSampleDataSource(
"AdventureWorksDW""OLEDB-MD", _ 
SQL Server Reporting Service - Deployment by command line        
"data source=localhost;initial catalog=Adventure Works DW"
SQL Server Reporting Service - Deployment by command line
SQL Server Reporting Service - Deployment by command line    
'Publish the sample reports 
SQL Server Reporting Service - Deployment by command line
    PublishReport("Company Sales"
SQL Server Reporting Service - Deployment by command line    PublishReport(
"Employee Sales Summary"
SQL Server Reporting Service - Deployment by command line    PublishReport(
"Product Catalog"
SQL Server Reporting Service - Deployment by command line    PublishReport(
"Product Line Sales"
SQL Server Reporting Service - Deployment by command line    PublishReport(
"Sales Order Detail"
SQL Server Reporting Service - Deployment by command line    PublishReport(
"Territory Sales Drilldown"
SQL Server Reporting Service - Deployment by command line
SQL Server Reporting Service - Deployment by command line
End Sub
 
SQL Server Reporting Service - Deployment by command line
SQL Server Reporting Service - Deployment by command lineSQL Server Reporting Service - Deployment by command line
Public Sub CreateSampleDataSource()Sub CreateSampleDataSource(name As String, extension As String, connectionString As String
SQL Server Reporting Service - Deployment by command line    
'Define the data source definition. 
SQL Server Reporting Service - Deployment by command line
    Dim definition As New DataSourceDefinition() 
SQL Server Reporting Service - Deployment by command line    definition.CredentialRetrieval 
= CredentialRetrievalEnum.Integrated 
SQL Server Reporting Service - Deployment by command line    definition.ConnectString 
= connectionString 
SQL Server Reporting Service - Deployment by command line    definition.Enabled 
= True 
SQL Server Reporting Service - Deployment by command line    definition.EnabledSpecified 
= True 
SQL Server Reporting Service - Deployment by command line    definition.Extension 
= extension 
SQL Server Reporting Service - Deployment by command line    definition.ImpersonateUser 
= False 
SQL Server Reporting Service - Deployment by command line    definition.ImpersonateUserSpecified 
= True 
SQL Server Reporting Service - Deployment by command line    
'Use the default prompt string. 
SQL Server Reporting Service - Deployment by command line
    definition.Prompt = Nothing 
SQL Server Reporting Service - Deployment by command line    definition.WindowsCredentials 
= False 
SQL Server Reporting Service - Deployment by command line
SQL Server Reporting Service - Deployment by command line
Try 
SQL Server Reporting Service - Deployment by command line    rs.CreateDataSource(name, parentPath, 
False, definition, Nothing
SQL Server Reporting Service - Deployment by command line    Console.WriteLine(
"Data source {0} created successfully", name) 
SQL Server Reporting Service - Deployment by command line
SQL Server Reporting Service - Deployment by command line
Catch e As Exception 
SQL Server Reporting Service - Deployment by command line    Console.WriteLine(e.Message) 
SQL Server Reporting Service - Deployment by command line
End Try 
SQL Server Reporting Service - Deployment by command line
End Sub
 
SQL Server Reporting Service - Deployment by command line
SQL Server Reporting Service - Deployment by command lineSQL Server Reporting Service - Deployment by command line
Public Sub PublishReport()Sub PublishReport(ByVal reportName As String
SQL Server Reporting Service - Deployment by command line    
Try 
SQL Server Reporting Service - Deployment by command line        
Dim stream As FileStream = File.OpenRead(filePath + reportName + ".rdl"
SQL Server Reporting Service - Deployment by command line        definition 
= New [Byte](stream.Length) {} 
SQL Server Reporting Service - Deployment by command line        stream.Read(definition, 
0CInt(stream.Length)) 
SQL Server Reporting Service - Deployment by command line        stream.Close() 
SQL Server Reporting Service - Deployment by command line
SQL Server Reporting Service - Deployment by command line    
Catch e As IOException 
SQL Server Reporting Service - Deployment by command line        Console.WriteLine(e.Message) 
SQL Server Reporting Service - Deployment by command line    
End Try 
SQL Server Reporting Service - Deployment by command line
SQL Server Reporting Service - Deployment by command line    
Try 
SQL Server Reporting Service - Deployment by command line        warnings 
= rs.CreateReport(reportName, parentPath, False, definition, Nothing
SQL Server Reporting Service - Deployment by command line
SQL Server Reporting Service - Deployment by command line        
If Not (warnings Is NothingThen 
SQL Server Reporting Service - Deployment by command line            
Dim warning As Warning 
SQL Server Reporting Service - Deployment by command line            
For Each warning In warnings 
SQL Server Reporting Service - Deployment by command line                Console.WriteLine(warning.Message) 
SQL Server Reporting Service - Deployment by command line            
Next warning 
SQL Server Reporting Service - Deployment by command line
SQL Server Reporting Service - Deployment by command line        
Else 
SQL Server Reporting Service - Deployment by command line            Console.WriteLine(
"Report: {0} published successfully with no warnings", reportName) 
SQL Server Reporting Service - Deployment by command line        
End If 
SQL Server Reporting Service - Deployment by command line
SQL Server Reporting Service - Deployment by command line    
Catch e As Exception 
SQL Server Reporting Service - Deployment by command line        Console.WriteLine(e.Message) 
SQL Server Reporting Service - Deployment by command line    
End Try 
SQL Server Reporting Service - Deployment by command line
End Sub
 

 

Except some RS server code, we can get all clear method for Upload report or configuration Data Sources, then you can use them into your own script.

For example:

SQL Server Reporting Service - Deployment by command lineRS -"PublishReports.rss" -"http://[ReportServer]/ReportServer/"

Use above command you can deploy your reports easily.

In next post I will share some best practice to use RS.exe deploy TFS reports.

Thanks!

上一篇:不用闪存了,Optane SSD为何还要28%的OP?


下一篇:python opencv 基础形状查找 实例