Reporting Services Styles in a Database Table
Article published in SQL Server Central on 2009/03/26
As it was previously discussed by Adam Aspin in his series Add Styles to Your Reportng Services Reports on SQLServerCentral, it is very useful to be able to change various report attributes, such as colours and borders properties, in a centralised way just like by using CSS files or Skins. Currently, Reporitng Services does not allow us to use a similar approach, so Adam showed us how to apply a “style” to a report by using custom code in Reporting Services – either by embedding the code for all attriibutes directly in the report, or by referencing an external source. However, there is another way to handle such attributes and that is by storing them in a database table. There are certain advantages in doing so, but there could be some disadvantages, as well.
I would suggest to keep your database tables stroing values such as report attributes, Reporting Services environment settings (for using dynamically generated javascript) and other dynamic report properties separated by naming them in a unified way. I have used the CTL (for control) prefix in the past. For illustrative purposes I will provide a simple definition of a database table called CTLReportColours:
HeaderColour nvarchar(10),
FooterColour nvarchar(10),
BodyTextColour nvarchar(10)
)
We can either retrieve the values from the database table in a sotred procedure we are already using on our report, or we can create a new one, specifically built for getting report attributes. We can use the first approach if our report uses one data set only. Then we can assign all report items to that data set and simply use the Fields collection items in our expressions. However, if we have multiple data sets assigned to different report items, such as tables(ixes), we may find that we need to code the retrieval of our report attributes in many many stored procedures. To overcome this limitation, we can ceate a spearate stored procedure, which returns the set of values stored in the database table. A simple example is code like:
CREATE usp_CTL_Get_Report_Colours
AS
BEGIN
SELECT HeaderColour
, FooterColour
, BodyTextColour
FROM CTLReportColours
END
Data Set
· We do not need to know anything about coding to create dynamic reports
· Reports are dynamic with no need to re-deploy them
· Report attributes are in a database table, which makes their management easy
· Various management screens can be built on top of the database table in .NET with relative ease
· Retireving the values through a stored procedures allows us to pass back parameters, which then can drive what colours get displayed – making the retrieval flexible if we need to display different colours for different departments or people
· Centralised and secured storage to all report attributes – environment settings, styles, etc.
If you enjoyed this post, make sure you subscribe to my RSS feed!
Related posts:
- Interactive reports – passing content back to the database
- Speed up MDX query preparation in Reporting Services
- Advanced javascript in Reporting Services
 
Very nice blog. I have referenced it as a high value resource. You can see the post at:
http://robertlambrecht.spaces.live.com/blog/cns!1738EAC7F6359C6D!2077.entry