Monday, March 12, 2012

RS utility parameters

I'm trying to use the rs utility on the command line, but all the examples I've found use only 1 parameter. I want to use multiple parameters and have not been able to get it working. Can anyone advise if this is possible, and if so, how to do it.

Thanks in advance

Jez

Hi,

following the script (rss) file definition that accepts the datasource from the rs command line stmt.

myfile.rss

Dim definition As [Byte]() = Nothing
Dim warnings As Warning() = Nothing
Dim parentFolder As String = "MyReports"
Dim parentPath As String = "/" + parentFolder
Dim filePath As String = "C:\Reports\"

Public Sub Main()

rs.Credentials = System.Net.CredentialCache.DefaultCredentials
Dim name As String

'Create the parent folder
Try
rs.CreateFolder(parentFolder, "/", Nothing)
Console.WriteLine("Parent folder created: {0}", parentFolder)
Catch e As Exception
Console.WriteLine(e.Message)
End Try

'Create the WOS shared data source
CreateDataSource()

'Publish the reports
PublishReport("Report1")
PublishReport("Report2")

End Sub

Public Sub CreateDataSource()
Dim name As String = "AFES_DB"
Dim parent As String = "/" + parentFolder

'Define the data source definition.
Dim definition As New DataSourceDefinition()
definition.CredentialRetrieval = CredentialRetrievalEnum.Store
definition.ConnectString = "data source=" & datasource & ";initial catalog=NorthWind"
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
definition.UserName = "sa"
definition.Password = ""

Try
rs.CreateDataSource(name, parent, True, definition, Nothing)

Catch e As Exception
Console.WriteLine(e.Message)
End Try

End Sub

Public Sub PublishReport(ByVal reportName As String)
Try
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
Console.WriteLine(e.Message)
End Try

Try
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

Else
Console.WriteLine("Report: {0} published successfully with no warnings", reportName)
End If

Catch e As Exception
Console.WriteLine(e.Message)
End Try
End Sub

the rs command should be as follows

rs -i myfile.rss -s http://localhost/reportserver -v datasource=cpc2

u can also send the ParentFolder name from the command line. all u need to do is remove the statement Dim parentFolder As String = "MyReports" in the above rss file and add the value in the command line as follows

rs -i myfile.rss -s http://localhost/reportserver -v datasource=cpc2 -v parentFolder=myReports

if u wanna add few more parameters just use the -v switch followed by name and value.

|||

Thanks - I got it working

|||

Hi Chakra,

Your post is very useful for me too. But I have another issue. How to pass date-type parameter?

I am having trouble passing date type parameter into my report and always getting "Default value or value provided for the report parameter 'myParam' is not a valid value".

Thanks in advance,

Man

No comments:

Post a Comment