Lesson 3: Load a Report Definition from the Report Server


Applies To: SQL Server 2016

After you have created your project and generated the classes from the RDL schema, you are ready to load a report definition from the report server.

To load a report definition

  1. Add a private field at the top of the ReportUpdater class (module if you are using Visual Basic) for the Report class. This field will be used to maintain a reference to report that is loaded from the report server for the life of the application.

    private Report _report;
  2. Replace the code for the LoadReportDefinition() method in the Program.cs file (Module1.vb for Visual Basic) with the following code:

    private void LoadReportDefinition()
        System.Console.WriteLine("Loading Report Definition");
        string reportPath = 
            "/AdventureWorks 2012 Sample Reports/Company Sales 2012";
        // Retrieve the report defintion 
        // from the report server
        byte[] bytes = 
        if (bytes != null)
            XmlSerializer serializer = 
                new XmlSerializer(typeof(Report));
            // Load the report bytes into a memory stream
            using (MemoryStream stream = new MemoryStream(bytes))
                // Deserialize the report stream to an 
                // instance of the Report class
                _report = (Report)serializer.Deserialize(stream);

In the next lesson, you will write code to update the report definition that was loaded from the report server. See Lesson 4: Update the Report Definition Programmatically.

Updating Reports Using Classes Generated from the RDL Schema (SSRS Tutorial)
Report Definition Language (SSRS)

Community Additions