'Modify RDL Definition Using SQL
Hi I'm trying to modify over 100 ssrs rdl files to include some standard text in the report header so i thought the easiest option would be to modify the rdl definition in the reportserver database where i've ran into 2 issues
- when my new XML includes
<rd:DefaultName>ReportPrivacyLabel</rd:DefaultName>
i get the following error which must be related to namespace not sure how to resolve this
XML parsing: line 24, character 17, undeclared prefix
- when
<rd:DefaultName>ReportPrivacyLabel</rd:DefaultName>
is not included in the new XML my sql query doesn't modify my rdl xml
Any advice would be greatly appreciated
DECLARE @myDoc XML;
SET @myDoc = N'
<Report MustUnderstand="df" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns:df="http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition/defaultfontfamily">
<df:DefaultFontFamily>Segoe UI</df:DefaultFontFamily>
<ReportSections>
<ReportSection>
<Page>
<PageHeader>
<Height>1.75543cm</Height>
<PrintOnFirstPage>true</PrintOnFirstPage>
<PrintOnLastPage>true</PrintOnLastPage>
<ReportItems>
<Textbox Name="ReportName">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>=Globals!ReportName</Value>
<Style>
<FontSize>16pt</FontSize>
</Style>
</TextRun>
</TextRuns>
<Style />
</Paragraph>
</Paragraphs>
<rd:DefaultName>ReportName</rd:DefaultName>
<Top>0.30903cm</Top>
<Left>0.5842cm</Left>
<Height>0.83283cm</Height>
<Width>12.63883cm</Width>
<Style>
<Border>
<Style>None</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
<!-- THIS IS WHERE I WANT TO INSERT NEW XML -->
</ReportItems>
<Style>
<Border>
<Style>None</Style>
</Border>
</Style>
</PageHeader>
<PageFooter>
<Height>1.35467cm</Height>
<PrintOnFirstPage>true</PrintOnFirstPage>
<PrintOnLastPage>true</PrintOnLastPage>
<Style>
<Border>
<Style>None</Style>
</Border>
</Style>
</PageFooter>
<PageHeight>29.7cm</PageHeight>
<PageWidth>21cm</PageWidth>
<LeftMargin>2cm</LeftMargin>
<RightMargin>2cm</RightMargin>
<TopMargin>2cm</TopMargin>
<BottomMargin>2cm</BottomMargin>
<ColumnSpacing>0.13cm</ColumnSpacing>
<Style />
</Page>
</ReportSection>
</ReportSections>
</Report>'
DECLARE @newFeatures XML;
SET @newFeatures = N'
<Textbox Name="ReportPrivacyLabel">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>Secret and Confidential</Value>
<Style>
<FontStyle>Normal</FontStyle>
<FontFamily>Consolas</FontFamily>
<FontWeight>Normal</FontWeight>
<TextDecoration>None</TextDecoration>
<Color>Red</Color>
</Style>
</TextRun>
</TextRuns>
<Style>
<FontSize>10pt</FontSize>
</Style>
</Paragraph>
</Paragraphs>
<rd:DefaultName>ReportPrivacyLabel</rd:DefaultName>
<Top>1.15543cm</Top>
<Left>0.5842cm</Left>
<Height>0.6cm</Height>
<Width>6.77567cm</Width>
<ZIndex>1</ZIndex>
<Style>
<Border>
<Style>None</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>';
SET @myDoc.modify('
insert sql:variable("@newFeatures") as last
into (/Report/ReportSections/ReportSection/Page/PageHeader/ReportItems)[1] ')
SELECT @myDoc;
GO
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|