find a location for property in a new city

Friday, 6 January 2012

How to run Crystal Reports on Azure

Here is a step by step guide on how to make an ASP.NET project that uses Crystal Reports run successfully on Azure. If you try to run a Crystal Report in your ASP.NET site without the Crystal Reports runtime installed you will receive a "System.Runtime.InteropServices.COMException" with description "The Report Application Server failed".

The problem is that you need to install the Crystal Reports runtime. This isn't a problem with regular hosting since you can just install Crystal Reports on each of your servers and off you go.

With Azure, though, if you remote into the machine and install it, it will work fine until your deployment is redistributed to another machine which it will do at some point due to the nature of cloud computing.

How to install Crystal Reports on your Azure web role

Fortunately it is still easy with Azure. Easy when you know how anyway. Here are the steps you will need to take:

First of all you will need to download the SAP Crystal Reports runtime engine for .NET Framework 4 (64-bit). This should extract as a msi file called CRRuntime_64bit_13_0_2.msi.

In your web application in Visual Studio you should paste this msi file at the route of your web project and include it in the project. Right click it in the Solution Explorer and set its 'Build Action' to 'None' and also set its 'Copy to Output Directory' to 'Always Copy'.

Next you will create a command file to execute this msi file. Create a new text file, call it StartUp.cmd and then save it in the root of your web project (next to the msi). In that file write the following:

@ECHO off

ECHO "Starting CrystalReports Installation" >> log.txt
msiexec.exe /I "CRRuntime_64bit_13_0_2.msi" /qn
ECHO "Completed CrystalReports Installation" >> log.txt

Set the properties of StartUp.cmd to 'Build Action' = 'None' and 'Copy to Output Directory' = 'Always Copy'.

Now in your ServiceDefinition.csdef make this cmd file a start up task by adding the following lines:

<WebRole name="Web" vmsize="Small">
  ...
  <Startup>
    <Task commandLine="StartUp.cmd" executionContext="elevated" taskType="background" />
  </Startup>
</WebRole>

You are now instructing each instance that starts up with your package to run the Crystal Reports msi file that installs the runtime on the instance ready for its use in Azure.

A few Crystal Reports on Azure tips

I ran into a few bits and bobs which caused me unnecessary pain along the seemingly clean process outlined above. I will share them with you in case you do too in no particular order.

  • Make sure your .rpt Crystal Report files are set to Build Action: Content and Copy to Output Directory: Copy always.
  • Don't be alarmed with how long it takes to deploy. It will take much longer to upload than usual because you are now uploading an extra 77MB of installation files. It took me an hour to deploy on my home connection!
  • Ignore all the warnings about how your web project is dependent on various Crystal Report assemblies since Azure will have them just as soon as your installation file runs.
  • Configure a remote desktop connection when you do your deployments since it will be invaluable should anything go wrong and at an hour per deployment you don't want to be messing about.
  • Visual Studio may have added a load of random assemblies in your web.config you are not aware of and don't need and may even cause problems like log4net.

That is all. Good luck - it's very satisfying when you get it going.

Follow britishdev on Twitter

7 comments:

  1. I followed this along with partial success, but that's probably a version thing [it's now May 2012].

    My Azure webrole is on an x64 server, and I'm developing in vs2010, with .Net 4.0. Crystal runtime is up to 13.0.3.

    The big issue is the 'undefined bobj' error, which I think is being caused because IIS is installed on D: on the Azure server. Does Crystal look for the viewer on C:?

    My work around, if it helps, was found here http://social.msdn.microsoft.com/Forums/en-CA/vscrystalreports/thread/ef56f72b-7ede-47d8-ba9e-9e63b9ac0203.

    Bascially copy all the viewer files from the aspnet_client\system_web\4_0_30319 to a sub-directory of your project, fill in the sections in your web.config as shown in the link above, and it works.

    ReplyDelete
  2. Great instruction, all works. But I have one problem: I have a report with dynamic parameter and from local computer I have a list of items from combo box. But when I upload it to Azure and I view report, I have to enter value to textbox (like in static parameter).

    I connect to Azure database.

    ReplyDelete
  3. Nice article, and I have implemented the same as you posted, but i am unable to publish to Azure.
    I am getting the below error when I click on Publish

    Error 64 Exception of type 'System.OutOfMemoryException' was thrown. C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\Windows Azure Tools\1.7\Microsoft.WindowsAzure.targets 2814 5 WindowsAzure1

    Can you help on this?

    ReplyDelete
  4. this way is good one to install crystall reports but it akes too much time .
    alternatively we can use .bat file and powershell to run crystal reports on azure
    it is very fast ,whole procedure is finished in 20 minutes.

    ReplyDelete
  5. Hi!!
    Can you show me the way to do it with a .bt and powershell?
    May be it's posible to host the engine into a Blob and create an Script to download it and install it, but I don't know how.

    ReplyDelete
  6. Hi, I uploaded to Windows Azure a WebSite that uses Crystal Reports.

    I'm not using a Virtual Machine, but a "Standard Web Site". Is this tutorial specific for virtual Machine? If it isn't, where "ServiceDefinition.csdef" comes from??

    Regads.

    ReplyDelete
  7. Hi Colin, I moved to Cloud Servive and followed your steps, but it crash with log4net.dll: “Could not load file or assembly ‘log4net’ or one of its dependencies.”, and log4net is not included in my web.config.

    Did you face this problem?

    Thanks

    ReplyDelete