Click here to Skip to main content
11,924,800 members (60,763 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


5 bookmarked

SSRS Production Deployment: Part 3

, 6 May 2013 Apache
Rate this:
Please Sign up or sign in to vote.
Deploying reports


In Part 2, we talked about deploying SSRS data sources. Now we are ready for reports.

Reports are deployed using rs.CreateReport() method. It accepts array of bytes instead of .rdl file name. This is relatively minor, since reading contents of a file is not that hard. Here’s the code:

Dim len As Integer
Dim fileBytes As Byte()
Using stream As FileStream = File.OpenRead(path)
    len = stream.Length
    fileBytes = New [Byte](len - 1) {}
    stream.Read(fileBytes, 0, len)
End Using

rs.CreateReport("MyReport", "Reports Folder", overwrite, fileBytes, Nothing)

It would be even easier if Microsoft did not mess up the VB example at the above link: they don’t read the last byte of the stream and the result is invalid XML. Interestingly, in the SQL 2000 example, they messed up the array initialization instead, so they send an extra byte to the SSRS server instead. The result is the server complaining about illegal 0×00 character at the end of the report.

It seems difficult to comprehend, even for Microsoft people, that in VB.NET, the number of elements in your array is different from the number you specify in Dim.

Updating Data Source References

Another hurdle is that report definitions, as stored by BIDS, contain invalid data source references. When you upload a report as outlined above, you will get a warning similar to this:

The dataset `DataSet1' refers to the shared data source `MyDataSource', 
which is not published on the report server.

HTTP traffic sniffing shows that when BIDS deploys a report, it gets the same warning. The solution is to update the data source references after the report has been uploaded, changing them to existing data sources in the "/Data Sources" folder.

This requires several steps. First, we need to load the report file as XML and locate all data source references.

Dim doc As System.Xml.XmlDocument = New System.Xml.XmlDocument()

Dim nsManager As XmlNamespaceManager = New XmlNamespaceManager(doc.NameTable)
nsManager.AddNamespace("r", "")
Dim nodes As XmlNodeList = doc.SelectNodes("/r:Report/r:DataSources/r:DataSource/r:DataSourceReference", 

Then we need to convert those nodes to DataSource objects recognized by SSRS:

Dim dataSources As DataSource() = New DataSource(nodes.Count - 1) {}

For i As Integer = 0 To nodes.Count - 1
    dataSources(i) = CreateDataSourceObj(nodes.Item(i))

Private Function CreateDataSourceObj(ByVal refNode As XmlNode) As DataSource

    Dim reference As DataSourceReference = New DataSourceReference
    reference.Reference = "/Data Sources/" + refNode.InnerText

    Dim result As DataSource = New DataSource
    result.Name = CType(refNode.ParentNode, XmlElement).GetAttribute("Name")
    result.Item = reference

    Return result
End Function

And finally, we need to call rs.SetItemDataSources method:

rs.SetItemDataSources(serverReportPath, dataSources)

The complete code for creating a report is here.
The combined file for creating a data source and a report is here.

It was fun, isn’t it? I am not sure why Microsoft did not make it simpler: SSRS reports are typically needed in an enterprise environment, and production deployment is an important part of development for the enterprise. It would also help if the code sample for CreateReport were right: I spent quite some time trying to figure out why I am getting weird exceptions from SSRS before I noticed the size error.

I hope this text will save others hours of boilerplate coding and frustration.


This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0


About the Author

Ivan Krivyakov
Technical Lead Thomson Reuters
United States United States
Ivan is a hands-on software architect/technical lead working for Thomson Reuters in the New York City area. At present I am mostly building complex multi-threaded WPF application for the financial sector, but I am also interested in cloud computing, web development, mobile development, etc.

Please visit my web site:

You may also be interested in...

Comments and Discussions

QuestionSSRS Deployment using rs.exe Pin
tr.anup6-Dec-13 13:12
membertr.anup6-Dec-13 13:12 
GeneralMy vote of 5 Pin
Mihai MOGA13-Jun-13 21:53
memberMihai MOGA13-Jun-13 21:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.151125.3 | Last Updated 6 May 2013
Article Copyright 2013 by Ivan Krivyakov
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid