【问题标题】:The attempt to connect to the report server failed - Setting URL and Path in ASP.NET?连接到报表服务器的尝试失败 - 在 ASP.NET 中设置 URL 和路径?
【发布时间】:2013-12-11 20:04:35
【问题描述】:

我正在尝试使用 ASP.NET Web 应用程序连接到 Report(rdlc 文件)。我正在使用 VS2010,Report Server 是 2008 版。

我有以下工作正常的报告 URL:

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

当我在浏览器中输入该 URL 时,它首先要求输入用户名密码。当我登录时,Report 显示得很好。

现在我需要在Report Viewer 中显示此报告。所以我在我的aspx 页面上添加了一个Report Viewer 控件。我为它配置了 URls:

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

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

我不确定这是否正确..?

无论如何,在我的PageLoad 中,我有以下代码行:

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

ReposrtCredentials 类取自:http://social.msdn.microsoft.com/Forums/en-US/vsreportcontrols/thread/c65abca7-0fdb-40fb-aabe-718f63377a55/(来自 Phil)

现在当我运行我的 Web 应用程序时,我收到以下错误:

连接到报表服务器的尝试失败。检查你的 连接信息并且报表服务器是兼容的 版本。

现在我不确定我提供给Report Viewer 的网址是否正确?或者还有什么问题。

有人知道吗..?

【问题讨论】:

  • 报告的路径始终是 reportserver+ reportpath,因此在您的情况下,它似乎是 server url/Products/_Layouts/ReportServer/Products/Dashboards/Product_tool.rdl...&DefaultItemOpen=1。 . 验证此网址是否正确。通常,报告 url 通常具有报告服务器 url + 目录 + 报告名称,即server url/Products/_layouts/ReportServer/Products/Dashboards/ReportName
  • @ManishMishra 当我转到:http://server/ReportServer 时,它会显示一个 Index (这就是它的名称吗?)。所以我基本上使用我的网络浏览器浏览目录。当我使用此 URL:http://server/ReportServer/Products/Dashboards/Product_tool.rdl 时,它仍然向我显示同一页面。这是否表明rdl 必须位于不同的路径?
  • 见@w00,你可能遇到了身份验证问题,当你想在asp.net web应用程序中显示SSRS报告时,你应该考虑实现IReportServerConnection2接口;等待我的解决方案,如何使用这个界面

标签: asp.net reporting-services reportviewer report-viewer2010


【解决方案1】:

要将 SSRS 报告集成到 ASP.NET 应用程序中,请执行以下步骤。

首先,实现IReportServerConnection2接口。我做了这样的事情:

  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;
            }
        }
    }

现在在您的 Configuration AppSettings 中放置以下键(或从任何您想要的地方提供这些值):

    <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"/>

现在,在您的 .aspx 页面中,拖动一个类似这样的 reportViewer:

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

并在 codeBehind.. 中配置您的 ReportViewer 正确放置您的ReportParameter

它会给你一个想法......

重点是,您需要正确地进行身份验证,因此编写您的自定义 ReportServerConnection

【讨论】:

  • 谢谢,认证并不是真正的问题。我收到此错误是因为 报告路径 错误。我找到了正确的 URL 并且它现在可以工作了。我正在使用 rdl 文件的完整 URL。
  • 感谢 w00,非常有帮助的评论,它终于让我走上了正轨。
  • @w00 - 您如何找到正确的报告路径?我目前正在使用这个:mardom-sql-srv01/Reports/Pages/…
【解决方案2】:

当您配置报表查看器时,请检查您使用的帐户是否有权查看报表,因为在使用服务器报表时您必须具有访问权限。 也看看这个链接。他们会有所帮助:http://forums.asp.net/t/1562624.aspx/1

【讨论】:

  • 谢谢,对我来说导入部分是我需要使用我的 RDL 文件的完整 URL。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-27
  • 1970-01-01
  • 2016-08-23
  • 1970-01-01
相关资源
最近更新 更多