Interesting Errors with RS.EXE

Few months back we have created a MSI using WIX, which calls the RS.EXE, to upload the RDLs into Report Server. Few days back there was a request from one fo the users that the MSI should backup the RDL from the server before overwriting with the new RDL.

The idea was that user would select the report which needs to be backed up and also provide the path where the backup needs to be placed.

I started with creating a small .RSS file which will just accept the backup folder name and create one if it does not exists. The code looked like

Dim strBackupFolder As String = BackupPath
Dim strBackupYesNo As String = BackupYesNo   

Public Sub Main()

‘rs.Credentials = System.Net.CredentialCache.DefaultCredentials

 If strBackupYesNo =”Yes” Then

  If CreateFolder(strBackupFolder) <> 1
   Return
  End If   

 End If
       

End Sub

Private Function CreateFolder(strFolderName As String) As Integer

 Dim i AS Integer =0
 Try
  If(Not System.IO.Directory.Exists(strFolderName)) Then
   System.IO.Directory.CreateDirectory(strFolderName)
  End If       
  i = 1
 Catch ex1 As SoapException
     Console.WriteLine(“Error occurred when creating folder: ” + strFolderName + ” : ” + ex1.Message )
 End Try  
 
 Return i
 
End Function

On firing the command

 “rs.exe” -i “e:\test\CreateFolder.rss” -s “http://servername/reports” -v BackupYesNo=”Yes”  -v BackupPath=”e:\test\dir1\”

I got the error “Could not connect to server: http://servername/reports/ReportService2005.asmx“. After some digging I realized that the report server should be called with “ReportServer” and “Reports”. So I changed my command line as

“rs.exe” -i “e:\test\CreateFolder.rss” -s “http://servername/reportserver” -v BackupYesNo=”Yes”  -v BackupPath=”e:\test\dir1\”

It again failed but with different error. It had thrown an error like “c:\user\rs.exe is not a valid Win32 application.”

I understood that my command line could not recognize the RS.EXE but no clue on the reason. I googled but of no use. After spending considerable time, I decided to call the RS.EXE with full path. So I did a search for RS.EXE in my Windows directory. To my surprise I got two entries, one in “..\Microsoft SQL Server\100\Tools\Binn” and another in the user folder. The RS.EXE in the user folder was having size as zero. I don’t know how it got created but I was sure that the size & place it was residing was not correct. So I simply deleted the file with zero bytes.

After deletion, the command line was able to recognize the RS.EXE but it thrown the below error

Unhandled exception:
Illegal characters in path.

The path looked fine but RS.EXE did not accept it. So I added one more line in RSS before the folder creation step to print the path passed as parameter. That is modified the code as

Private Function CreateFolder(strFolderName As String) As Integer

 Dim i AS Integer =0
 Try
  Console.WriteLine(strBackupFolder)
  If(Not System.IO.Directory.Exists(strFolderName)) Then
   System.IO.Directory.CreateDirectory(strFolderName)
  End If       
  i = 1
 Catch ex1 As SoapException
     Console.WriteLine(“Error occurred when creating folder: ” + strFolderName + ” : ” + ex1.Message )
 End Try  

Return i
 
End Function

 and the output was


A double quote was added at the end of the path. If you have observed the my backup path , you will see that it has a backslash “\” at the end. In C# this is used to escape characters. It looked as if the RS.EXE did the same thing here by escaping a double quote. Though I could not confirm this.

So I had to again modify my RSS script to remove the double quote from the parameter. So modified the line where I assign the BackupPath variable to “strBackupFolder” as

Dim strBackupFolder As String =  BackupPath.SubString(0,BackupPath.Length-1) 

I could do this without any concern as I know my MSI always adds the backslash at the end of the path. Once I added this everything worked fine that is it created a folder if does not exists already.

Then I wanted to add one more parameter, that is of the Report Name which I wanted to back up.

I modified the RSS script to accept one more parameter by adding

Dim myreportName As String = reportName
and printing the name in the main procedure.

Then tried to call the RSS from command line as

“rs.exe” -i “e:\test\CreateFolder.rss” -s “http://servername/reportserver” -v BackupYesNo=”Yes”  -v BackupPath=”e:\test\dir1\” -v reportName=”abc”

which resulted in one more error 😦 I was really fed-up with this but no other option than to fix it.

It thrown an error like

The specified script failed to compile with the following errors:
C:\Users\sudilli> “C:\Windows\Microsoft.NET\Framework\v2.0.50727\vbc.exe” /t:exe
 /main:MainModule /utf8output /R:”System.dll” /R:”System.Xml.dll” /R:”System.Web
.Services.dll” /R:”C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\rs
.exe” /out:”C:\Users\sudilli\AppData\Local\Temp\1\siosjljb.exe” /debug-  “C:\Use
rs\sudilli\AppData\Local\Temp\1\siosjljb.0.vb” “C:\Users\sudilli\AppData\Local\T
emp\1\siosjljb.1.vb”
Microsoft (R) Visual Basic Compiler version 8.0.50727.4927
for Microsoft (R) .NET Framework version 2.0.50727.4927
Copyright (c) Microsoft Corporation.  All rights reserved.

C:\Users\sudilli\AppData\Local\Temp\1\siosjljb.1.vb(18) : error BC30451: Name ‘r
eportName’ is not declared.

    Dim myreportName As String = reportName
                                 ~~~~~~~~~~
C:\Users\sudilli\AppData\Local\Temp\1\siosjljb.1.vb(26) : error BC30451: Name ‘r
eportName’ is not declared.

    Console.writeline(reportName)
                      ~~~~~~~~~~

I tried many things like copy pasting the variable (assuming I could have mis-spelt), renaming the variable etc.. But nothing worked. I removed the newly added varaible and commented the correspoding line in the RSS and it worked fine.  I was at loss to understand why RS.EXE did not recognize the new variable.

Again I added the variable this time at the front (by chance which is called as luck :)) and the command executed without any issues. Then I realized that the issue could be with the path (which escapes some characters). I was able to reproduce the issue by adding the variable after the path. So I kept the path variable at the end and the script worked fine. At last  I was able to complete the backing up of RDL (of course I included more lines of code in the RSS) from Report Server.

But still I am not able to identify the reasons for the strange behaviours of RS.EXE. Planning to post it in MSDN forum.

Advertisements

About Suresh Kumar D

Hardcore SQL Developer and aspiring Database Architect.
This entry was posted in SSRS. Bookmark the permalink.

2 Responses to Interesting Errors with RS.EXE

  1. Chris says:

    Just wanted to say, I looked at various pages, but yours where the only one to sort it out for me! Took me 2 hours to find it thou..But many thanks

  2. Murali says:

    Since this is an old post not sure if you’ve already figured the issue out. But the error you were getting on the reportName could be because of –

    -v BackupPath=”e:\test\dir1\”

    if you had instead used –

    -v BackupPath=”e:\test\dir1\\”

    it might have worked. rs.exe treats the backslash quote as quote being escaped so it tries to complete the command at that point thereby not recognizing the reportName as an additional input. Just a guess based on the error message.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s