Getting Started with SSRS on Azure

In this post I will describe how to get started with running SQL Server Reporting Services on Azure.  SSRS on Azure is now in beta stage, but anyone can give it a whirl. 

First of all, activate the service and create new report server.  When you are on management portal, click on Reporting link (see below).

Now click on the following button

Now pick subscription and server location.  Try to pick it to be in the same data server as your SQL Azure database you will report on.

Now fill in user and password.  You will need this information later, so write it down.

Click finish to complete the setup.  You will see newly created server on the screen.  You will also need the url from the screen below.

 

Now I am going to create an ASPX page I will use to display reports in my MVC application that I will deploy to Azure.  It will use Azure database to store the data as well.  You can read more about MVC and SSRS in my previous post – http://dotnetspeak.com/index.php/2012/02/using-ssrs-in-asp-net-mvc-application/.  Here I am going to describe the differences from that solution.

One important thing to notice is that SSRS on Azure does not support Windows authentication, so we have to use credentials property of the SSRS ASPX control.  First, let’s take a look at the ASPX portion of the form.  It is pretty simple:

 

<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="reportForm" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
        <rsweb:ReportViewer ID="mainReportViewer" AsyncRendering="false" runat="server" Width="840px" Height="700px">
        </rsweb:ReportViewer>
    </div>
    </form>
</body>
</html>

Code behind just needs to set credentials.  I do not want to hard-code them, so I am adding those to web.config, and I am just using Configuration Manager to get to those.

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                
                mainReportViewer.ServerReport.ReportServerUrl =
                    new Uri(ConfigurationManager.AppSettings["ReportServerUrl"]);
                mainReportViewer.ServerReport.ReportPath =
                    string.Format(ConfigurationManager.AppSettings["ReportPath"], (data.ReportFileName));
                mainReportViewer.ProcessingMode = ProcessingMode.Remote;
                mainReportViewer.ShowParameterPrompts = false;
                mainReportViewer.ShowRefreshButton = false;
                mainReportViewer.ShowWaitControlCancelLink = false;
                mainReportViewer.ShowBackButton = false;
                mainReportViewer.ShowCredentialPrompts = false;
                string userName = ConfigurationManager.AppSettings["ReportServerUserName"];
                string password = ConfigurationManager.AppSettings["ReportServerPassword"];
                if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password))
                {
                    mainReportViewer.ServerReport.ReportServerCredentials =
                        new ReportServerCredentials
                            {
                                UserName = userName,
                                UserPassword = password
                            };
                }
                // set parameters if needed                
                mainReportViewer.ServerReport.Refresh();
            }
        }

My ReportServerCredentials class is super simple, and just needs to implement the interface report viewer expects.

using Microsoft.Reporting.WebForms;

namespace MyApp.Reports
{
    public class ReportServerCredentials : IReportServerCredentials
    {

        public string UserName { get; set; }
        public string UserPassword { get; set; }
        public bool GetFormsCredentials(out System.Net.Cookie authCookie, out string userName, out string password, out string authority)
        {
            authCookie = null;
            userName = UserName;
            password = UserPassword;
            authority = "";
            return true;
        }

        public System.Security.Principal.WindowsIdentity ImpersonationUser
        {
            get { return null; }
        }
        public System.Net.ICredentials NetworkCredentials
        {
            get { return null; }
        }
    }
}

The actual credentials are the same as the ones you set up initially when you created the SSRS Server instance.

 

Now, you have to create the actual reports, using the standard SSRS reports project.  The key difference is that you need to set SQL Server version in the properties of the project to SQL Azure.  Another thing that makes the whole process simple is to setup a Shared Data Source and setup credentials for it.  Those are the credentials you setup in SQL Azure when setting up the database, not the ones you used for SSRS Server, although you could use the same, one less thing to remember.  Then you can use the same data source for all your reports.  The reports themselves are exactly the same, no difference whatsoever between SSRS Azure and SSRS on Windows.  You can deploy to Azure by using the same Deploy menu, available when you right click on the project.  You will get prompted for your SSRS Azure credentials again at that time.  Once you deployed those and your web application, your reports should now work.  Please review my previous post on setting up web.config with an http handler for reports.

Thanks and enjoy.

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *