Using rs.exe utility to deploy reports

  • Hi All,

    I am using the below given code..to deploy and assign a shared data source to reports....The reports are deployed successfully but the database is not assigned - It throws an error "data source not found" though the data source exists in the root directory.....

    'VBScript source code

    Dim definition As [Byte]() = Nothing

    Dim warnings As Warning() = Nothing

    Dim messageLogFileName As String = ".\PublishLogFile.txt"

    Public Sub Main()

    'define variables

    Dim dataSourceName As String = "localhost"

    Dim initialCatalogName As String = "wfx"

    Dim parentDirectoryName As String = "wfxwebreports"

    Dim createFolder As boolean = true

    Dim createDataSource As boolean = true

    rs.Credentials = System.Net.CredentialCache.DefaultCredentials

    ' ********* Create the parent folder

    If(createFolder) Then

    Try

    rs.CreateFolder(parentDirectoryName , "/", Nothing)

    Catch e As Exception

    LogMessage("Error creating Parent folder " + parentDirectoryName + " :" + e.Message)

    goto exitloop

    End Try

    Else

    LogMessage("New Parent folder " + parentDirectoryName + " will not be created")

    End If

    ' ********* Create Host Data Source

    If(createDataSource) Then

    Try

    CreateHOSDataSource("192.16.1.16",datasourcename,"wx",parentDirectoryName)

    LogMessage("Host Data Source " + dataSourceName + " created" )

    Catch e As Exception

    LogMessage("Error creating Host Data Source " + dataSourceName + ": " + e.Message)

    goto exitloop

    End Try

    Else

    LogMessage("New Data Source " + dataSourceName + " will not be created")

    End If

    ' ******************* LIST OF REPORTS TO PUBLISH *********************

    PublishReport("C:\WFX_Uploads","rptAllowanceAnalysisDetail", parentDirectoryName)

    PublishReport("C:\WFX_Uploads","rptAbstractStockValue", parentDirectoryName)

    PublishReport("C:\WFX_Uploads","rptAllowanceAnalysis", parentDirectoryName)

    dim rpt1 as string = "/" & parentdirectoryname & "/" & "rptAllowanceAnalysisDetail"

    dim rpt2 as string = "/" & parentdirectoryname & "/" & "rptAbstractStockValue"

    console.writeline(rpt1)

    SetReportDatasource(rpt1)

    SetReportDatasource(rpt2)

    'rs.SetItemDataSources (Item As String,"sqlserver")

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

    exitloop:

    End Sub

    Public Sub CreateHOSDataSource(ByVal sqlServer As String, ByVal dataSource As String, ByVal initialCatalog As String, ByVal parentDirectory As String)

    'Define the data source definition.

    Dim definition As New DataSourceDefinition()

    definition.CredentialRetrieval = CredentialRetrievalEnum.Integrated

    definition.ConnectString = "data source=" & sqlServer & ";initial catalog=" & initialCatalog

    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

    parentdirectory="/" & parentdirectory

    'Console.WriteLine(parentdirectory)

    rs.CreateDataSource(dataSource, parentDirectory, true, definition, Nothing)

    End Sub

    Public Sub PublishReport(ByVal filePath As String, ByVal reportName As String, ByVal parentPath As String)

    Try

    LogMessage(filePath + "\" + reportName + ".rdl")

    LogMessage(parentpath)

    parentpath="/" & parentpath

    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

    LogMessage("Error Reading Report File " + reportName + ": " + e.Message)

    End Try

    Try

    warnings = rs.CreateReport(reportName, parentPath, True, definition, Nothing)

    If Not (warnings Is Nothing) Then

    Dim warning As Warning

    LogMessage("Report " + reportName + " published successfully with the following warnings")

    For Each warning In warnings

    LogMessage(warning.Message)

    Next warning

    Else

    LogMessage("Report " + reportName + " published successfully with no warnings")

    End If

    Catch e As Exception

    LogMessage("Error Publishing Report " + reportName + ": " + e.Message)

    End Try

    End Sub

    Public Sub LogMessage(ByVal msgString As String)

    Try

    Dim myLog As StreamWriter = File.AppendText(messageLogFileName)

    myLog.WriteLine("{0} {1} {2}", DateTime.Now.ToLongTimeString(), DateTime.Now.ToLongDateString(), msgString)

    myLog.Flush()

    myLog.Close()

    Console.WriteLine(msgString)

    Catch e As IOException

    Console.WriteLine("Error Opening Log File " + messageLogFileName + ": " + e.Message)

    End Try

    End Sub

    Public sub SetReportDatasource(Byval Item as string)

    Dim dataSources() As DataSource = rs.GetItemDatasources(item)

    console.writeline(datasources(0).name)

    Dim ds As New DataSource()

    ds=datasources(0)

    ds.Name = "localhost"

    dataSources(0) = ds

    Dim refrence As New DataSourceReference()

    refrence.Reference = "/wfxwebreports/localhost"

    ds.Item = CType(refrence, DataSourceDefinitionOrReference)

    console.writeline(datasources(0).name)

    Try

    rs.SetItemDataSources(item,dataSources)

    Console.WriteLine("New reference set for the report.")

    Catch e As SoapException

    Console.WriteLine(e.Detail.InnerXml.ToString())

    LOGMESSAGE(e.Detail.InnerXml.ToString())

    End Try

    End Sub

    Regards,
    [font="Verdana"]Sqlfrenzy[/font]

  • Have you looked at the Reporting Services Scripter by Jasper Smith:

    http://www.sqldbatips.com/showarticle.asp?ID=62

    Not trying to be funny, but you are kind of reinventing the wheel, you just probably don't realize it. I use the RSScripter to manage all of my Reporting Services deployments and migrations.

    Jonathan Kehayias | Principal Consultant | MCM: SQL Server 2008
    My Blog | Twitter | MVP Profile
    Training | Consulting | Become a SQLskills Insider
    Troubleshooting SQL Server: A Guide for Accidental DBAs[/url]

  • Jonathan Kehayias (12/19/2008)


    Have you looked at the Reporting Services Scripter by Jasper Smith:

    http://www.sqldbatips.com/showarticle.asp?ID=62

    Not trying to be funny, but you are kind of reinventing the wheel, you just probably don't realize it. I use the RSScripter to manage all of my Reporting Services deployments and migrations.

    Thanks...how can I deploy reports using RSScriptor.......

    However I still want to know how it is done.....???

    Regards,
    [font="Verdana"]Sqlfrenzy[/font]

  • Jasper uses the webservice extensions for Reporting Services which are self documenting in the SOAP output.

    Jonathan Kehayias | Principal Consultant | MCM: SQL Server 2008
    My Blog | Twitter | MVP Profile
    Training | Consulting | Become a SQLskills Insider
    Troubleshooting SQL Server: A Guide for Accidental DBAs[/url]

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply