Skip to content

Instantly share code, notes, and snippets.

@tckz
Created November 15, 2012 09:50
Show Gist options
  • Save tckz/4077734 to your computer and use it in GitHub Desktop.
Save tckz/4077734 to your computer and use it in GitHub Desktop.
SSRSにレポート配置
@echo off
set RS_EXE="C:\Program Files\Microsoft SQL Server\110\Tools\Binn\rs.exe"
cd %~dp0
@rem For newer endpoint. -e Mgmt2010
%RS_EXE% -i deploy.rss -s http://IPorHostname/reportserver -v filePath=. -v parentFolder=/ -v "dataSourcePath=/データ ソース/" -v dataSourceName=SomeName
if errorlevel 1 (
echo *** Some error occurred
goto :eout
)
:eout
pause
' SEE http://weblogs.sqlteam.com/tarad/archive/2005/01/05/3944.aspx
' -v parentFolder=/nr/ or /
' -v filePath=dir
' -v dataSourcePath=/nr/
' -v dataSourceName=SomeName
Public Sub Main()
rs.Credentials = System.Net.CredentialCache.DefaultCredentials
Dim fileList As String() = Directory.GetFiles(filePath)
Dim fileName As String
For Each fileName In fileList
If System.IO.Path.GetExtension(fileName) = ".rdl" Then
PublishReport(System.IO.Path.GetFullPath(fileName))
End If
Next
End Sub
Public Sub PublishReport(ByVal fileName As String)
Dim definition As [Byte]() = Nothing
Dim warnings As Warning() = Nothing
Dim reportName As String
reportName = System.IO.Path.GetFileNameWithoutExtension(fileName)
Console.WriteLine("Processing: {0}", fileName)
Try
Dim stream As FileStream = File.OpenRead(fileName)
definition = New [Byte](stream.Length-1) {}
stream.Read(definition, 0, CInt(stream.Length))
stream.Close()
Catch e As IOException
Console.WriteLine(e.Message)
Throw
End Try
Try
Dim parentPath As String = parentFolder
If parentPath.EndsWith("/") And parentPath <> "/"
parentPath = parentPath.Substring(0, parentPath.Length - 1)
End If
' Newer
'rs.CreateCatalogItem("Report", reportName, parentPath, True, definition, Nothing, warnings)
' Older
warnings = rs.CreateReport(reportName, parentPath, True, definition, Nothing)
If Not (warnings Is Nothing) Then
Dim warning As Warning
For Each warning In warnings
Console.WriteLine(warning.Message)
Next warning
End If
Dim dataSources As DataSource() = rs.GetItemDataSources(parentFolder + reportName)
Dim itemDataSource As DataSource
For Each itemDataSource In dataSources
Dim newDS As New DataSource()
Dim dsRef As New DataSourceReference()
dsRef.Reference = dataSourcePath + dataSourceName
newDS.Item = dsRef
newDS.Name = dataSourceName
Dim newDataSources As DataSource() = New DataSource(){newDS}
rs.SetItemDataSources(parentFolder + reportName, newDataSources)
Next itemDataSource
Catch e As Exception
Console.WriteLine(e.Message)
Throw
End Try
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment