4

I'm trying to connect to a Report (rdlc file) using ASP.NET Web Applications. I'm working with VS2010 and the Report Server is version 2008.

I have the following URL to the report which works fine:

http://server url/Products/_layouts/ReportServer/RSViewerPage.aspx?rv:RelativeReportUrl=/Products/Dashboards/Product_tool.rdl&Source=Server Url/Products/Dashboards/Forms/AllItems.aspx&DefaultItemOpen=1

When i enter that URL in my browser it first asks for a username password. When i log in then the Report shows up just fine.

Now i need to display this report in a Report Viewer. So i added a Report Viewer control to my aspx page. I configured the URls for it like so:

Report Server:** http://server url/Products/_layouts/ReportServer

Report Path:** /Products/Dashboards/Product_tool.rdl

I'm not really sure if that is even correct..?

In any case, in my PageLoad i have the following line of code:

eportViewer1.ServerReport.ReportServerCredentials = new ReportCredentials("myuser", "mypass");

The ReposrtCredentials class is taken from: http://social.msdn.microsoft.com/Forums/en-US/vsreportcontrols/thread/c65abca7-0fdb-40fb-aabe-718f63377a55/ (from Phil)

Now when i run my Web Application i get the following error:

The attempt to connect to the report server failed. Check your connection information and that the report server is a compatible version.

Now i'm not sure if the URL i supplied to the Report Viewer is right? Or what the problem else could be.

Anyone any idea..?

w00
  • 26,172
  • 30
  • 101
  • 147
  • path to a report is always reportserver+ reportpath, hence in your case it seems to be http://server url/Products/_Layouts/ReportServer/Products/Dashboards/Product_tool.rdl...&DefaultItemOpen=1.. verify if this url is correct. Typically, a report url generally has reportserver url + directory + report name i.e. http://server url/Products/_layouts/ReportServer/Products/Dashboards/ReportName – Manish Mishra Jan 16 '13 at 12:41
  • @ManishMishra When i goto: `http://server/ReportServer` it then displays an **Index** (is that what its called?). So i cab basically browse through directories using my web browser. When i use this URL: `http://server/ReportServer/Products/Dashboards/Product_tool.rdl` then it still shows me the same page. Is that a sign that the `rdl` must be located at a different path? – w00 Jan 16 '13 at 13:04
  • see @w00, you might b facing an authentication issue, when you want to display SSRS reports in asp.net web application, you should consider implementing IReportServerConnection2 interface; wait for my solution, to how to use this interface – Manish Mishra Jan 16 '13 at 13:38

2 Answers2

4

In order to Integrate SSRS Reports into an ASP.NET application, follow these steps.

Firstly, Implement IReportServerConnection2 interface. I did something like this:

  public sealed class CustomReportServerConnection : IReportServerConnection2
    {
        public WindowsIdentity ImpersonationUser
        {
            get
            {
                // Use the default Windows user.  Credentials will be
                // provided by the NetworkCredentials property.
                return null;
            }
        }
        public ICredentials NetworkCredentials
        {
            get
            {
                // Read the user information from the web.config file.  
                // By reading the information on demand instead of 
                // storing it, the credentials will not be stored in 
                // session, reducing the vulnerable surface area to the
                // web.config file, which can be secured with an ACL.

                // User name
                string userName = ConfigurationManager.AppSettings[Utility.Constants.AppConst.REPORT_USER].ToString(); 

                if (string.IsNullOrEmpty(userName))
                    throw new Exception(Utility.Constants.AppConst.MESSAGE_MISSING_USER_NAME);

                // Password
                string password = ConfigurationManager.AppSettings[Utility.Constants.AppConst.REPORT_PASSWORD].ToString();

                if (string.IsNullOrEmpty(password))
                    throw new Exception(Utility.Constants.AppConst.MESSAGE_MISSING_PWD);

                // Domain
                string domain = ConfigurationManager.AppSettings[Utility.Constants.AppConst.REPORTS_DOMAIN].ToString();

                if (string.IsNullOrEmpty(domain))
                    throw new Exception(Utility.Constants.AppConst.MESSAGE_MISSING_DOMAIN);

                return new NetworkCredential(userName, password, domain);
            }
        }
        public bool GetFormsCredentials(out Cookie authCookie, out string userName, out string password, out string authority)
        {
            authCookie = null;
            userName = null;
            password = null;
            authority = null;
            // Not using form credentials
            return false;
        }
        public Uri ReportServerUrl
        {
            get
            {
                string url = ConfigurationManager.AppSettings[Utility.Constants.AppConst.REPORT_SERVER_URL].ToString();

                if (string.IsNullOrEmpty(url))
                    throw new Exception(Utility.Constants.AppConst.MESSAGE_MISSING_URL);

                return new Uri(url);
            }
        }
        public int Timeout
        {
            get
            {
                return int.Parse(ConfigurationManager.AppSettings[Utility.Constants.AppConst.REPORT_SERVER_TIME_OUT].ToString());
                // return 60000; // 60 seconds
            }
        }
        public IEnumerable<Cookie> Cookies
        {
            get
            {
                // No custom cookies
                return null;
            }
        }
        public IEnumerable<string> Headers
        {
            get
            {
                // No custom headers
                return null;
            }
        }
    }

Now in your Configuration AppSettings place following keys ( or provide these values from wherever you want):

    <add key="ReportServerUrl" value="http://sqlServerURL/ReportServer_SQL2008R2"/>

    <!--Development TargetReportFolder-->
    <add key="TargetReportFolder" value="/AppReporting/"/>
    <add key="ReportServerTimeOut" value="600000"/>
    <add key="ReportViewerServerConnection" value="FullyQualified Name of ur CustomReportServerConnection,ProjectName"/>
    <add key="ReportsUser" value="ReportUser"/>
    <add key="ReportsPassword" value="reportPassword"/>
    <add key="ReportsDomain" value="myDomain"/>

Now , in your .aspx page, drag a reportViewer something like this:

<rsweb:ReportViewer ID="RptViewer" runat="server" AsyncRendering="False" SizeToReportContent="true"
            ProcessingMode="Remote" Width="100%" BackColor="#F7F8F9" OnReportError="RptViewer_ReportError"
            OnReportRefresh="RptViewer_ReportRefresh1" Height="">
        </rsweb:ReportViewer>

and configure your ReportViewer in the codeBehind.. place your ReportParameter properly.

it shud give you an idea...

point is, you need to authenticate properly, hence writing your custom ReportServerConnection

Manish Mishra
  • 12,163
  • 5
  • 35
  • 59
  • 2
    Thanks, authentication wasn't really the problem though. I got this error because the **Report Path** was wrong. I found the correct URLs and its working now. I'm using the full URL to the rdl file. – w00 Jan 16 '13 at 13:59
  • Thanks w00, very helpful comment, it finally put me on the right track. – AGuyCalledGerald Nov 20 '13 at 10:11
  • 1
    @w00 - How do you find the correct report path? I'm currently using this: http://mardom-sql-srv01/Reports/Pages/Report.aspx?ItemPath=%2fScorePorYears – ovatsug25 Aug 05 '16 at 13:28
1

When you configure your report viewer,check whether the account you use has permission to view the report because it is necessary that you have access when using server report. Check out this link too. They will be of help : http://forums.asp.net/t/1562624.aspx/1

Srinivas
  • 1,063
  • 7
  • 15
  • 1
    Thanks, the import part for me in there was that i needed to use the full URL to my RDL file. – w00 Jan 16 '13 at 13:59