Posts

Reporting off ADO.NET datasets using the RS 2005 XML Extension

In case you missed this little gem, RS 2005 comes with a brand new XML Extension which allows you to report off an XML data returned from an URL-addressable resource, such as an ASP.NET page or a web service. For example, suppose that you have a web method called GetOrders that return the customer orders as a typed dataset (table in my case) and has the following signature:


 


[WebMethod]


public CustomerOrders.SalesOrderHeaderDataTable GetOrders(int customerID)


 


You can create a report from the returned dataset by using the RS 2005 XML dataset extension:




  1. Create a data source that uses the XML extension by selecting XML as the data source type.


  2. Enter the URL address of the web service in the connection string, e.g. #


  3. Once the data source is ready, create a dataset with the following query:

 <Query>


   <Method Namespace=”http://tempuri.org/” Name=”GetOrders”/>


   <SoapAction>http://tempuri.org/GetOrders</SoapAction>


   <ElementPath IgnoreNamespaces=”true”>GetOrdersResponse/GetOrdersResult/diffgram/DocumentElement/SalesOrderHeader</ElementPath>


</Query>


 


Unfortunately, the documentation stays shy about all the parameters supported by the XML extension but it is fairly easy to deduce what’s going on here.


The Method element describes the web method to be called. This is somewhat redundant since the SoapAction element does the same and explained in more details here. The ElementPath describes the full XPATH to the elements to be retrieved and flattened in a two-dimensional resultset. Finally, the IgnoreNamespaces attribute tells the XML extension to ignore any schema namespaces when parsing the XML content.


 


   4. To pass a parameter(s) to the web method, use the Parameters tab and link the report parameter to the query parameter as usual, e.g:


 


Name                          Value


customerID              =Parameters!CustomerID.Value


 


One cautionary note that bit me really bad is that the parameter name is case-sensitive and must much the argument name of the web method verbatim. Thus, if you change the parameter Name to CustomerID, you will find out that the XML extension doesn’t pass the parameter value.


 


Thanks for to the XML Extension, in my cases, reporting off XML data from URL-addressable sources may not require a custom data extension with RS 2005. Happy reporting!

Harden MS Reporting Services Using Custom Extensions (Part 2 of 2)

The second part of my article for DevX.


In Part 1, you learned to create a custom security model for Microsoft Reporting Services. Now, tighten the screws by adding role membership authentication and stave off problems by troubleshooting and debugging your custom extensions ahead of time. 

Writing custom rendering extensions

As you probably know, the custom rendering specification wasn’t documented with RS 2000. The features set was there, only the information was lacking. The SQL Server 2005 Beta 2 documentation now includes the rendering extension specification.


James Yip has written an excellent article about writing custom rendering extensions in the February issue of the MSDN magazine. As you can imagine, custom renderers are not trivial to write. For this reason, I highly recommend you check for availability of third-party rendering extensions that support the rendering format you need before you embark on this journey. For example, as I mention in one of previous posts, SoftArtisians provides flexible Excel and Word rendering extensions.


Happy rendering!

Article here, article there…RS, RS everywhere

Some of my recent writings see daylight:



  • The publisher of my book donated Chapter 1 of my book (Introducing Microsoft Reporting Services) to The Code Project website. It is available for free access here http://www.codeproject.com/books/MSReportingServices.asp?msg=1015597#xx1015597xx

  • DevX published part 1 of my two-part article about RS Forms Authentication. It is available for free access here http://www.devx.com/dotnet/Article/26759.

  • MSDN has picked up my article first published by Pinnacle Publications  in the November issue of the Visual Basic Developer magazine. The article demonstrates how to leverage Reporting Services to generate reports on the server side of ASP.NET applications using a custom web control called AwReportViewer. You can read the article and download the sample code here (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnhcvb04/html/vb04k8.asp).

Service Pack 2 brings client-side printing

Printing reports was akward with RS 2000 to say the least. This was especially true when the reports were rendered in HTML since in this case the report is generated inside an IFRAME element. Since the frame could scroll right-clicking and engaging the standard browser printing was problematic. As a workaround, the report had to be exported in PDF format (or other non-HTML renderer) and printed as such.


You will be happy to know that SP2 puts this issue to rest by supporting client-side printing in the form of the new print control which allows printing of a report on the client side (inside the browser). This control makes printing a report a breeze. Once you install Service Pack 2 and request a report, you will see a new toolbar button added to the report toolbar (between the Refresh Report and Help buttons).


 


The print control is implemented as an ActiveX control. When you click on the Printer button, a request is made to download the print control if it is not installed already on the user machine. Once the download process is complete, the familiar Print Dialog is displayed.


 


As you can see, the print control supports also a preview mode.


 


Once the preview mode is initiated or the report is printed, the control instructs the Report Server to print the report using the EMF rendering extension. This is the same concept as the Bryan Keller’s article demonstrates.


The print control also supports a client-side object model (RSClientPrint object) to give developers access to the print control functionality should custom toolbars have to implemented.


Client-side printing has been one of most demanded RS features and the new print control solves this issue elegantly. For more information about SP2, please see my previous post.


Happy printing and reporting in the new 2005!

Where is my ecryption key gone?

As I stressed out in one of my previous posts and my book, it is an absolute must that you back up the RS encryption key as one of the first steps after you install RS and lock it up in a safe place. You can back up the encryption key this by using the rskeymgmt utility as follows:


rskeymgmt -e -f <filename> -p <password>


Trust me on this–sooner or later you will need that key. One situation when you will definately need it is after resetting the ASP.NET account either by explicitly invoking aspnet_regiis.exe or when installing a new version of the .NET framework. For example, recently I installed .NET Framework Beta 2 which effectively reset the ASP.NET account. This caused RS to invalidate the encryption key. As a result, when navigating to the Report Manager, I got the dreaded error:


“The report server cannot decrypt the symmetric key used to access sensitive or encrypted data in a report server database. You must either restore a backup key or delete all encrypted content and then restart the service.”


Panic will not help resolve this issue, but a copy of the encryption key will definetely help. Here are the steps to reset the encryption key if the ASP.NET account is reset:



  1. Recall where you saved the RS key. If you haven’t saved it or you can’t recall, try to extract the key by issuing
    rskeymgmt -e -f <filename> -p <password>

  2. Open the RSReportServer.config file and copy the installation ID GUID from the InstallationID node. The InstallationID node looks like this:
    <InstallationID>{7d8664d4-3bae-496b-b607-fbb5d0879c7c}</InstallationID>

  3. Delete the references to the old RS encyption key:
    rskeymgmt -r <installation id>

  4. Restart IIS and the Report Server windows service.

  5. Reapply the encryption key:
    rskeymgmt -a -f <filename from step 1> -p <password>

This should fix the error and you should be able to navigate to the Report Manager without any issues.


If you don’t have a backup copy of the key and you cannot extract it with rskeymgmt -e, than the only option is to delete the ecrypted content by issuing rskeymgmt -d


The net effect of this is that you will need to reenter the credentials of all data sources that use standard security because the credentials are stored in encrypted format.

Report-enable your web apps with Microsoft Reporting Services

Pinnacle Publications published this article in the November issue of the Visual Basic Developer magazine. The article demonstrates how to leverage Reporting Services to generate reports on the server side of ASP.NET applications. You need a paid subscription to read it and download the code. I hope MSDN will pick it up as well in the next month or so.

Export to Excel and Word with SoftArtisians’ OfficeWriter

Version 1.0 of Reporting Services doesn’t support exporting reports to Microsoft Word format. It does support exporting to Excel but developers have limited control over the Excel renderer. For example, you may need provide placeholders (bookmarks in Word or markers in Excel) which will be populated during runtime with fields from your report query.


SoftArtisians will release soon an RS version of their flagship product OfficeWriter which will bring flexible exporting to Excel and Word formats in the form of two additional rendering extensions. Currently, you can try out this product by subscribing to the SoftArtisians beta program here.


You will most likely find the process of creating a Word or Excel report with OfficeWriter very straightforward. For example, to create a Word report you need to:


1. Create a new Word file.


2. Using the SoftArtisians Word toolbar set up a new query. Unfortunately, the query is not saved in the Word file so you have to recreate it every time you need to make a change.


3. Create bookmarks in your Word document by inserting fields from the query. OfficeWriter supports repetative regions which allows you to generate tabular reports.


4. Deploy your report to Report Server. During this step, OfficeWriter will generate the report RDL file which you will find in the same folder where the original Word file is located.


Without a doubt, many report authors will find OfficeWriter useful when report requirements call for flexible rendering in Excel and Word.


 

Supercharge your reports with custom code

Microsoft has just published my article “Microsoft Reporting Services in Action: Extending Microsoft SQL Server 2000 Reporting Services with Custom Code“ on MSDN. Excerpted from my book Microsoft Reporting Services in Action, this article demonsrates how to implement advanced features in reports by integrating them with .NET assemblies.

Forms Authentication and RS Web Service


Often, report enabling Internet-facing applications require replacing the default RS Windows-based security with Forms Authentication. This allows clients to request reports by URL with the all the goodies that URL addressability entail, namely support for interactive features and the HTML Viewer toolbar. While RS Forms Authentication is well-documented (see the Forms Authentication whitepaper by Microsoft), something which may not be so obvious is that Forms Authentication can be used not only with URL addressability but also with the RS web service. 


Let’s say you want most of your reports to be requested by URL but some to be generated on the server-side of the application by SOAP. Or, you need to manage a Report Server installation configured for Forms Authentication from a WinForm client by calling the management SOAP APIs. The RS Forms Authentication model supports all these scenarios. All in all, it boils down to to storing the authentication ticket (cookie) received from the LogonUser call on the client side and passing it back with each request.


I whipped out a simple WinForm app (sorry C# only, but they are free converters out there for C#->VB ) to show how this could be done. This sample doesn’t have any bugs! Common, we all know this is not true :-). Please let me know if something buggy raises its ugly head. Usual disclaimers apply also…you are on your own basically.


DISCLAIMER: One thing that you may need definitely to change if you are planning to retrofit my code to a web app is way the app stores the cookie. You will notice that the sample app stores the cookie in a static class member. This is all fine with WinForm apps running on single thread by definitely no-no for web applications where you need to be aware of multi-threading and multi-user issues. If the web app is the same one that requests reports by URL, the simplest solution may be not to store the cookie at all but to get it from the current HTTP context, similar to the original implementation of the overridden proxy class that comes with the MS sample.

For time being, the sample Forms Authenticator app can be downloaded from
here.