忘れがちなことを、つらつらと...

俺的備忘録を公開してみるテスト

SQL Server 2008のReporting Service用に作成したレポートをExportする

結局、SQL Server自身のDBに保存されてるが、ある意味レポート定義のxml的なファイルである。

なので、DBダンプとかではなくて、テキストファイルで保管したい...

そのためのスクリプトが以下である。

Public Sub Main()
    Dim items() As CatalogItem
    Dim item As CatalogItem
    items = rs.ListChildren("/", True)

    For Each item In items
        Select Case item.Type
        Case ItemTypeEnum.Folder
            Directory.CreateDirectory(glbRootPath + item.Path)
        Case ItemTypeEnum.Report
            SaveToRDL(glbRootPath, item.Path)
        Case Else
        End Select
    Next item
End Sub

Sub SaveToRDL(rootPath, reportPath)
    Dim rptDefinition as byte() = Nothing
    Dim doc as new system.xml.xmlDocument
    Try
        rptDefinition = rs.GetReportDefinition(reportPath)
        Dim stream As New MemoryStream(rptDefinition)
        doc.Load(stream)
        doc.Save(rootPath + "\" + reportPath + ".rdl")
    Catch e As SoapException
        Console.WriteLine(e.Detail.InnerXml.ToString())
    Catch e As IOException
        Console.WriteLine(e.Message)
    End Try
End Sub

これを、例えば、rpt_exp.rssとかでテキスト保存する。

実行は、

rss.exe -i x:\rpt_exp.rss -s http://localhost/ReportSesrver -v glbRootPath = X:\bak

という感じで実行すればいい。パラメータ glbRootPath は、Exportしたファイルを保存するフォルダを指定。