Automatic deployment of Reporting Services reports

Source: Internet
Author: User

Because the Reporting Services reports in the project need to be automatically deployed, you can find them online.

There is a ready-made code, but it is still a problem

So I modified it. Meet project requirements

The script is as follows:

Dim definition As [Byte] () = Nothing
Dim warnings As Warning () = Nothing
'The Directory Name of the remote report data source, which does not support Chinese characters [this item needs to be modified]
Dim performancefoldername As String = "Data Sources"

'Data source name [this item needs to be modified]
Dim performancefilename As String = "PTDS_PW_conn"

'Directory path of the remote report data source
Dim performancefolderpath As String = "/" + performancefoldername

'Report directory nameall published reports are stored in this directory [this item needs to be modified]
Dim reportsFolderName As String = "PW"

'The upper-level Directory Name of the report. The root directory is "/". Only the root directory and the lower-level directory are supported. That is, the upper-level Directory Name of the report can be/aaa/at most. [This item needs to be modified]
Dim reportsfatherPath As String = "/ptds_reports"

'Report directory nameall published reports are stored in this directory path
Dim reportsFolderPath As String = reportsfatherPath + "/" + reportsFolderName

'Designed report storage path. That is, the local report path. [This item needs to be modified]
Dim filePath As String = "E: \ Report Project1 \"

'Link string [this item needs to be modified]
Dim connectionString As String = "Data Source = 192.168.1.4; Initial Catalog = PTDS3; Connect Timeout = 120"

'Database username [this item needs to be modified]
Dim UsernameString As String = "sa"

'Database password [this item needs to be modified]
Dim PasswordString As String = "sa12345"

Public Sub Main ()
ReportsFolderPath = reportsFolderPath. Replace ("//","/")
Rs. Credentials = System. Net. CredentialCache. DefaultCredentials
'Create a report directory. The parameter represents (Folder name, folder directory)
CreateReportFolder (reportsFolderName, reportsfatherPath)
'Create DataSource directory
CreateReportFolder (performancefoldername, performancefolderpath)
'Create a data source
CreateDataSource (performancefolderpath)
'Deployment report'
DeployRepors (filePath)
End Sub

'Create a directory
Public Sub CreateReportFolder (ByVal reportFolder As String, ByVal reportpath As String)
Dim pathname As String
Try
'Create Reports Folder
If (reportpath. Length> 1) then
Try
Pathname = reportpath. Substring (reportpath. LastIndexOf ("/") + 1)
Rs. CreateFolder (pathname, "/", Nothing)
Console. WriteLine ("Create Folder success: {0}", pathname)
Catch e As Exception
Console. WriteLine ("Create Folder Error. But is does not influence the Application" + e. message)
End Try
End If
Rs. CreateFolder (reportFolder, reportpath, Nothing)
Console. WriteLine ("Create Folder success: {0}", reportFolder)
Catch e As Exception
Console. WriteLine ("Create Folder Error. But is does not influence the Application" + e. message)
End Try

End Sub

'Deployment report'
Public Sub DeployRepors (ByVal filePath As String)

Dim tempFileAry As String ()
Dim reportFilePath as String
TempFileAry = Directory. GetFiles (filepath)
For Each reportFilePath In tempFileAry
Dim fileName As String

FileName = reportFilePath. Substring (reportFilePath. LastIndexOf ("\") + 1)
Dim fileSuffix As String
FileSuffix = fileName. Substring (fileName. LastIndexOf (".") + 1)
Select Case fileSuffix
Case "rdl", "png"
PublishReport (fileName, fileSuffix)
End Select
Next

End Sub
'*************************************** ***************************
* Create a data source (test successful )**************
'*************************************** ****************************
Public Sub CreateDataSource (ByVal sourceFolder As String)

Dim name As String = performancefilename
'Define the data source definition.
Dim definition As New DataSourceDefinition ()
Dim dSource As New DataSource ()
Dsource. Item = definition
Definition. CredentialRetrieval = CredentialRetrievalEnum. Store
Definition. ConnectString = connectionString
Definition. UserName = UsernameString
Definition. Password = PasswordString
Definition. Enabled = True
Definition. EnabledSpecified = True
Definition. Extension = "SQL"
Definition. ImpersonateUser = False
Definition. ImpersonateUserSpecified = True
'Use the default prompt string.
Definition. Prompt = Nothing
Definition. WindowsCredentials = False
Dsource. Name = performancefolderpath

Try
Rs. CreateDataSource (name, sourceFolder, true, definition, Nothing)
Console. WriteLine ("Create Data Source: {0} ERROR", name)
Catch e As Exception
Console. WriteLine ("Create Data Source error" + e. message)
End Try

End Sub

'*************************************** ***************
*********
'*************************************** ****************

Public Sub PublishReport (ByVal reportName As String, ByVal fileSuffix As String)
Try

Dim stream As FileStream = File. OpenRead (filePath + reportName)
Definition = New [Byte] (stream. Length ){}
Stream. Read (definition, 0, CInt (stream. Length ))
Stream. Close ()
Catch e As IOException
Console. WriteLine ("report ")
End Try

Try
'*********************** ParentPath
If (fileSuffix = "rdl") Then
Dim str_reportname as String
Str_reportname = reportName. Substring (0, reportName. LastIndexOf ("."))
Console. WriteLine ("str_reportname: {0}", str_reportname)
Warnings = rs. CreateReport (str_reportname, reportsFolderPath, true, definition, Nothing)
SetReportDataSourceRef (reportName)
Else If (fileSuffix = "png") Then
Rs. CreateResource (reportName, reportsFolderPath, true, definition, "png", Nothing)
End If
If Not (warnings Is Nothing) Then
Dim warning As Warning
For Each warning In warnings
Console. WriteLine ("warning:" + 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 + "report publishing failed ")
End Try
End Sub

'*************************************** *********************************
*********************** ***************
'*************************************** *********************************
Public Sub SetReportDataSourceRef (ByVal reportName As String)
Try
Dim reference As DataSourceReference = New DataSourceReference
Dim ds As DataSource = New DataSource
Reference. Reference = performancefolderpath + "/" + performancefilename
Dim str_reportname as String
Str_reportname = reportName. Substring (0, reportName. LastIndexOf ("."))
Dim dsArray As DataSource () = rs. GetItemDataSources (reportsFolderPath + "/" + str_reportname)
Ds = dsArray (0)
Ds. Item = CType (reference, DataSourceReference)

Rs. SetItemDataSources (reportsFolderPath + "/" + str_reportname, dsArray)
Catch _ exception As Exception
Console. WriteLine ("aaa" + _ exception. message)
End Try
End Sub

 

Usage instructions: Save the above script as deploy. rss

Create a new deploy. dat batch file and run the above script

Deploy. bat content

Rs-I deploy. rss-s http: // 192.168.0.88/ReportServer-u userName-p password

Double-click deploy. bat to automatically publish the report to the http: // 192.168.0.88/ReportServer server.

 

 

Rs.exe parameter description

RUN -- CMD
C: \ Documents ents and Settings \ junmy> rs /?
Microsoft (R) Reporting Services RS
Version 9.00.1399.00 x86
Execute the script file based on the specified Report Server.
RS-I input file-s serverURL [-u user name] [-p Password]
[-L timeout] [-B] [-e endpoint] [-v var = value] [-t]

-I: script file to be executed in the input file
-S serverURL execution script
URL (including server and vroot ).
-U user name is used to log on to the server.
-P password is used to log on to the server.
-E: the Web service endpoint to be used with the script.
Options:
Exec2005-ReportExecution2005 endpoint
Mgmt2005-ReportService2005 endpoint
Mgmt2000-(not recommended) ReportService endpoint
-L timeout before connecting to the server
The number of seconds that have timed out. The default value is 60 seconds. 0 indicates
Infinite timeout.
-B runs in batches and rolls back if the command fails.
-V var = variable and value passed to the script
-T tracking contains tracking information in error messages

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.