The attempt to connect to the report server failed - Setting URL and Path in ASP.NET?

w00 picture w00 · Jan 16, 2013 · Viewed 43.4k times · Source

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..?

Answer

Manish Mishra picture Manish Mishra · Jan 16, 2013

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