none
Sub-report Rendering in SSRS 2008

    Question

  • I have a main report with a Sub-report embedded.  Sub-report and the main report have their own Protected Overrides Sub OnInit() inside the code section and instantiating the same class with the same name.  On BI Development Studio, it previews fine but when I print or save the report,  Sub-report portion of the main report is always blank.  So I did the following.

    Created the following outside the Sub-report’s OnInit() function:

     

    Public TestMessage As String = "Didn't go into OnInit"

     

    And inside the OnInit function, I did the following:

     

    TestMessage = "Inside OnInit"

     

    And created a TextBox and displays the following expression on the Sub-report:

     

    =Code.TestMessage

     

    Now when I preview the main report it shows the whole Sub-report as well as "Inside OnInit".

     

    But when I print it or save as PDF, it shows the following only in the Sub-report portion of the main report:

     

     

    "Didn't go into OnInit"

     

    So when it is rendering it is not going into the Sub-report's Oninit() function.  Is this a bug or am I doing something wrong?   Any help would be greatly appreciated.

     

    Thank you.



    Tuesday, March 24, 2009 3:06 PM

Answers

  • Well, I am almost 100% sure, that OnInit is actually called in these cases exactly once for subreport instances in RS 2008 - but only during the original processing of the subreport's datasets and data regions, which usually happens on the initial request that establishes your user session.  

    So if the initial request generates all pages of the report, you may get "lucky" in the way you use the local instance variable defined in the custom code, because OnInit was called upfront. 

    However, if you view the report page-by-page, every subsequent page request is a separate call to the server to render a specific page.  Those individual requests in RS 2008 do not invoke OnInit on subreport instances.  It seems like you are trying to get the semantics of "session variables", which is not available in Reporting Services today.  The closest you can get are either the usage of static variables (i.e. "shared" keyword in VB; they have a lifetime across individual requests), or see if report/group variables are sufficient for your particular scenario.

    That said, we are considering providing a built-in concept along the lines of "session variables" in a future release of Reporting Services.

    Probably not the answers you wanted, but at least I hope it clarifies why you are seeing this particular behavior.

    HTH,
    Robert
    Robert Bruckner   http://blogs.msdn.com/robertbruckner
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Thursday, March 26, 2009 2:36 AM

All replies

  • Are you running RS 2008 RTM, or with the latest cumulative update (http://support.microsoft.com/kb/963036) installed?

    Robert Bruckner   http://blogs.msdn.com/robertbruckner

    This posting is provided "AS IS" with no warranties, and confers no rights.

    Tuesday, March 24, 2009 4:16 PM
  • I have installed these patches and SP1 CTP but still the same.  I called the Reports using Web Services and it works fine.  It was able to render in any format I want with full Sub-report in the main report.  So the problem is only when save as/ exporting from Preview or in the online Report Manager.
    Tuesday, March 24, 2009 5:29 PM
  • I have enclosed the code for both Sub-Report and Main-Report.  Very simple reports.  But it still gives me the same result: It is not going into the Sub-Report's Protected Overrides Sub OnInit() when you render from Preview or online Report Manager.

    Here is the Sub-Report Code:

    <?xml version="1.0" encoding="utf-8"?>  
    <Report xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition">  
      <Body> 
        <ReportItems> 
          <Textbox Name="Textbox1">  
            <CanGrow>true</CanGrow> 
            <KeepTogether>true</KeepTogether> 
            <Paragraphs> 
              <Paragraph> 
                <TextRuns> 
                  <TextRun> 
                    <Value>=Code.TestMessage</Value> 
                    <Style /> 
                  </TextRun> 
                </TextRuns> 
                <Style /> 
              </Paragraph> 
            </Paragraphs> 
            <rd:DefaultName>Textbox1</rd:DefaultName> 
            <Height>0.25in</Height> 
            <Width>6.5in</Width> 
            <Style> 
              <Border> 
                <Style>None</Style> 
              </Border> 
              <PaddingLeft>2pt</PaddingLeft> 
              <PaddingRight>2pt</PaddingRight> 
              <PaddingTop>2pt</PaddingTop> 
              <PaddingBottom>2pt</PaddingBottom> 
            </Style> 
          </Textbox> 
        </ReportItems> 
        <Height>0.25in</Height> 
        <Style /> 
      </Body> 
      <Code>Public TestMessage As String = "Didn't go into OnInit" 
     
    Protected Overrides Sub OnInit()   
     
        TestMessage = "Inside OnInit" 
     
    End Sub</Code> 
      <Width>6.5in</Width> 
      <Page> 
        <LeftMargin>1in</LeftMargin> 
        <RightMargin>1in</RightMargin> 
        <TopMargin>1in</TopMargin> 
        <BottomMargin>1in</BottomMargin> 
        <Style /> 
      </Page> 
      <rd:ReportID>57961943-f698-4e96-b9c4-12358170feac</rd:ReportID> 
      <rd:ReportUnitType>Inch</rd:ReportUnitType> 
    </Report> 

    Here is the Main-Report Code:

    <?xml version="1.0" encoding="utf-8"?>  
    <Report xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition">  
      <Body> 
        <ReportItems> 
          <Subreport Name="Subreport1">  
            <ReportName>Sub-Report</ReportName> 
            <Height>0.48958in</Height> 
            <Width>6.5in</Width> 
            <Style> 
              <Border> 
                <Style>None</Style> 
              </Border> 
            </Style> 
          </Subreport> 
          <Textbox Name="Textbox1">  
            <CanGrow>true</CanGrow> 
            <KeepTogether>true</KeepTogether> 
            <Paragraphs> 
              <Paragraph> 
                <TextRuns> 
                  <TextRun> 
                    <Value>This is Main Report</Value> 
                    <Style /> 
                  </TextRun> 
                </TextRuns> 
                <Style /> 
              </Paragraph> 
            </Paragraphs> 
            <rd:DefaultName>Textbox1</rd:DefaultName> 
            <Top>0.8925in</Top> 
            <Height>0.25in</Height> 
            <Width>6.5in</Width> 
            <ZIndex>1</ZIndex> 
            <Style> 
              <Border> 
                <Style>None</Style> 
              </Border> 
              <PaddingLeft>2pt</PaddingLeft> 
              <PaddingRight>2pt</PaddingRight> 
              <PaddingTop>2pt</PaddingTop> 
              <PaddingBottom>2pt</PaddingBottom> 
            </Style> 
          </Textbox> 
        </ReportItems> 
        <Height>1.39583in</Height> 
        <Style /> 
      </Body> 
      <Width>6.5in</Width> 
      <Page> 
        <LeftMargin>1in</LeftMargin> 
        <RightMargin>1in</RightMargin> 
        <TopMargin>1in</TopMargin> 
        <BottomMargin>1in</BottomMargin> 
        <Style /> 
      </Page> 
      <rd:ReportID>db55748a-3e37-4f80-81f2-bdd03f376ac6</rd:ReportID> 
      <rd:ReportUnitType>Inch</rd:ReportUnitType> 
    </Report> 
    Tuesday, March 24, 2009 7:21 PM
  • Well, I am almost 100% sure, that OnInit is actually called in these cases exactly once for subreport instances in RS 2008 - but only during the original processing of the subreport's datasets and data regions, which usually happens on the initial request that establishes your user session.  

    So if the initial request generates all pages of the report, you may get "lucky" in the way you use the local instance variable defined in the custom code, because OnInit was called upfront. 

    However, if you view the report page-by-page, every subsequent page request is a separate call to the server to render a specific page.  Those individual requests in RS 2008 do not invoke OnInit on subreport instances.  It seems like you are trying to get the semantics of "session variables", which is not available in Reporting Services today.  The closest you can get are either the usage of static variables (i.e. "shared" keyword in VB; they have a lifetime across individual requests), or see if report/group variables are sufficient for your particular scenario.

    That said, we are considering providing a built-in concept along the lines of "session variables" in a future release of Reporting Services.

    Probably not the answers you wanted, but at least I hope it clarifies why you are seeing this particular behavior.

    HTH,
    Robert
    Robert Bruckner   http://blogs.msdn.com/robertbruckner
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Thursday, March 26, 2009 2:36 AM
  • Hi Robert,

    Thank you for your response.  In the past we were able to do this without any issue using SQL Server 2005 Reporting Services.  We had multiple Sub-Reports with Protected Overrides Sub OnInit() and they seem to work fine for us all the time.  Here is the same code done using SQL Server 2005 Reporting Services.

    Sub-Report

    <?xml version="1.0" encoding="utf-8"?>  
    <Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">  
      <InteractiveHeight>11in</InteractiveHeight> 
      <rd:DrawGrid>true</rd:DrawGrid> 
      <InteractiveWidth>8.5in</InteractiveWidth> 
      <rd:SnapToGrid>true</rd:SnapToGrid> 
      <RightMargin>1in</RightMargin> 
      <LeftMargin>1in</LeftMargin> 
      <BottomMargin>1in</BottomMargin> 
      <rd:ReportID>7ba350fc-3943-441d-9b7c-579c6565cfa3</rd:ReportID> 
      <Code> 
        Public TestMessage As String = "Didn't go into OnInit" 
     
        Protected Overrides Sub OnInit()  
     
        TestMessage = "Inside OnInit" 
     
        End Sub  
      </Code> 
      <Width>6.5in</Width> 
      <Body> 
        <ReportItems> 
          <Textbox Name="textbox1">  
            <rd:DefaultName>textbox1</rd:DefaultName> 
            <Top>0.375in</Top> 
            <Width>2.25in</Width> 
            <Style> 
              <PaddingLeft>2pt</PaddingLeft> 
              <PaddingRight>2pt</PaddingRight> 
              <PaddingTop>2pt</PaddingTop> 
              <PaddingBottom>2pt</PaddingBottom> 
            </Style> 
            <CanGrow>true</CanGrow> 
            <Left>0.25in</Left> 
            <Height>0.25in</Height> 
            <Value>=Code.TestMessage</Value> 
          </Textbox> 
        </ReportItems> 
        <Height>2in</Height> 
      </Body> 
      <Language>en-US</Language> 
      <TopMargin>1in</TopMargin> 
    </Report> 

    Main-Report

    <?xml version="1.0" encoding="utf-8"?>  
    <Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">  
      <InteractiveHeight>11in</InteractiveHeight> 
      <rd:DrawGrid>true</rd:DrawGrid> 
      <InteractiveWidth>8.5in</InteractiveWidth> 
      <rd:SnapToGrid>true</rd:SnapToGrid> 
      <RightMargin>1in</RightMargin> 
      <LeftMargin>1in</LeftMargin> 
      <BottomMargin>1in</BottomMargin> 
      <rd:ReportID>b1275ea9-40dd-426f-97e3-de60355c14d4</rd:ReportID> 
      <Width>6.5in</Width> 
      <Body> 
        <ReportItems> 
          <Subreport Name="subreport1">  
            <Top>0.25in</Top> 
            <ReportName>subReport1</ReportName> 
            <Width>6.125in</Width> 
            <Left>0.125in</Left> 
            <Height>0.5in</Height> 
          </Subreport> 
        </ReportItems> 
        <Height>3.25in</Height> 
      </Body> 
      <Language>en-US</Language> 
      <TopMargin>1in</TopMargin> 
    </Report> 

    I just hope that this function is not removed from SQL Server 2008 Reporting Services.

    Thank you again.

    Karnan Seevaratnam

    Thursday, March 26, 2009 6:46 PM
  • Anybody???

    Friday, April 03, 2009 1:08 PM