如何从询问登录凭据打开报表时停止Crystal报表查看器 [英] How to stop crystal report viewer from asking login credentials when opening subreport

查看:359
本文介绍了如何从询问登录凭据打开报表时停止Crystal报表查看器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我有嵌入在一个Visual Studio网站的Crystal报表。我部署网站上的IIS安装,并提供一个链接给用户,使他们能够在全球访问和查看此报告。该系统已伟大的工作。

然而,当我内嵌有一个子报告水晶报表,凭据没有被传递到子报表自动。当我调试解决方案,最初的报表打开罚款,当我点击该项目以打开子报表,水晶报表观众问我对数据库的登录凭据。

如何在code自动传递这些凭据,以便用户不要有在水晶报表查看器查看时输入code。

下面是code我在default.aspx.cs页中使用。它包含连接字符串。

 使用系统;
使用System.Collections.Generic;
使用System.Linq的;
使用的System.Web;
使用System.Web.UI程序;
使用System.Web.UI.WebControls;
使用System.Data.SqlClient的;命名空间CFIBInventory
{
    公共部分类_Default:System.Web.UI.Page
    {
        保护无效的Page_Load(对象发件人,EventArgs的发送)
        {
            SqlConnection的CON =新的SqlConnection(数据源= HPL-WTS;初始目录= Enterprise32;坚持安全信息= TRUE;用户ID = SA;密码= ********);
            数据集1 DS =新的数据集1();
            SqlDataAdapter的适配器=新的SqlDataAdapter(SELECT dbo.Material.Material code,dbo.Material.Category code,dbo.Material.Description,dbo.MaterialOnHand.Location code,dbo.Material.ValuationMethod, dbo.MaterialOnHand.Quantity FROM dbo.Material INNER JOIN dbo.MaterialOnHand ON dbo.Material.Material code = dbo.MaterialOnHand.Material code,其中(dbo.Material.Category code ='CFIB3')与(dbo.Material.ValuationMethod = 1)AND(dbo.Material.InactiveFlag = 0),CON);            adapter.Fill(ds.cfibInventory);
            CrystalReport1报告=新CrystalReport1();
            report.SetDataSource(DS);
            CrystalReportViewer1.ReportSource =报告;            CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
        }
    }
}

Crystal报表查看器通过以下code嵌入到我的.aspx页面中:

 <%@页标题=主页LANGUAGE =C#的MasterPageFile =〜/ Site.master母AutoEventWireup =真
    codeBehind =Default.aspx.cs继承=CFIBInventory._Default%GT;<%@注册装配=CrystalDecisions.Web,版本= 13.0.2000.0,文化=中性公钥= 692fbea5521e1304命名空间=CrystalDecisions.Web标签preFIX =CR%GT;< ASP:内容ID =HeaderContent=服务器ContentPlaceHolderID =HeadContent>
< META HTTP-EQUIV =X-UA-Compatible的内容=IE = 9/>
< / ASP:内容>
< ASP:内容ID =的BodyContent=服务器ContentPlaceHolderID =日程地址搜索Maincontent>
    &所述p为H.;
    &所述; / P>
    < CR:ID的CrystalReportViewer =CrystalReportViewer1=服务器
        AutoDataBind =真/>
< / ASP:内容>

有关子报表的查询是在子报告数据库专家。

顺便说一句,数据库连接到Windows Server 2005的计算机。我不相信它有公共接入的设置,比如自带的IIS。的previous报告,不具有子报表,安装一个新的2012服务器作为这就是在数据库上。不知道如果机器有什么用水晶报表查看器的附加登录提示。

任何帮助将是巨大的。谢谢你在前进!


编辑:从实施的NiMesh溶液后

嗯,我不过增加了连接的连接类型,Visual Studio是强调报告说:宣告前它不能使用局部变量报告。

的foreach(CrystalDecisions.CrystalReports.Engine.Table CrTable中的报表 .Database.Tables)

的foreach(报表的ReportDocument中的报表 .Subreports)

我注意到我宣布报告后下方为新crystalreport1。所以,我谨以上的NiMesh code块声明和红色下划线的报告消失了,但后来crtableLogoninfo的所有6个实例得到红色下划线的错误:crtableLogoninfo'的名称中不存在当前上下文

任何进一步的帮助,将大大AP preciated。

下面是我的code现在的样子:

 使用系统;
    使用System.Collections.Generic;
    使用System.Linq的;
    使用的System.Web;
    使用System.Web.UI程序;
    使用System.Web.UI.WebControls;
    使用System.Data.SqlClient的;
    使用CrystalDecisions.Shared;
    使用CrystalDecisions.CrystalReports.Engine;    命名空间CFIBInventory
    {
        公共部分类_Default:System.Web.UI.Page
        {
            保护无效的Page_Load(对象发件人,EventArgs的发送)
            {                //的NiMesh code
                ConnectionInfo crConnectionInfo =新ConnectionInfo();
                crConnectionInfo.ServerName =HPL-WTS
                crConnectionInfo.DatabaseName =Enterprise32;
                crConnectionInfo.UserID =SA;
                crConnectionInfo.Password =*********;                的foreach(CrystalDecisions.CrystalReports.Engine.Table CrTable在report.Database.Tables)
                {
                    crTableLogoninfo = CrTable.LogOnInfo;
                    crtableLogoninfo.ConnectionInfo = crConnectionInfo;
                    CrTable.ApplyLogOnInfo(crtableLogoninfo);
                }
                的foreach(在report.Subreports的ReportDocument报表)
                {
                    的foreach(CrystalDecisions.CrystalReports.Engine.Table CrTable在subreport.Database.Tables)
                    {
                        crtableLogoninfo = CrTable.LogOnInfo;
                        crtableLogoninfo.ConnectionInfo = crConnectionInfo;
                        CrTable.ApplyLogOnInfo(crtableLogoninfo);
                    }
                } //的NiMesh code结束                //旧的连接字符串,我想这不应该是在这里,因为的NiMesh code是连接
                // SqlConnection的CON =新的SqlConnection(数据源= HPL-WTS;初始目录= Enterprise32;坚持安全信息= TRUE;用户ID = SA;密码= 123qwerTy987);                数据集1 DS =新的数据集1();
                SqlDataAdapter的适配器=新的SqlDataAdapter(SELECT dbo.Material.Material code,dbo.Material.Category code,dbo.Material.Description,dbo.MaterialOnHand.Location code,dbo.Material.ValuationMethod, dbo.MaterialOnHand.Quantity FROM dbo.Material INNER JOIN dbo.MaterialOnHand ON dbo.Material.Material code = dbo.MaterialOnHand.Material code,其中(dbo.Material.Category code ='CFIB3')与(dbo.Material.ValuationMethod = 1)AND(dbo.Material.InactiveFlag = 0),CON);                adapter.Fill(ds.cfibInventory);                CrystalReport1报告=新CrystalReport1();                 // OLD code
                //report.SetDataSource(ds);
                CrystalReportViewer1.ReportSource =报告;                CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
            }
        }
    }


解决方案

这个问题在水晶报表的登录信息。显示报表之前,你必须登录信息设置为它们包括在主要报告及其子报告中的所有表。您正在使用的数据源断开报表中显示的方法。所以你不需要提供登录信息报告文件。你的问题就在这里。

  report.SetDataSource(DS);

当您使用的setDataSource方法,必须提供所包含水晶报表文档中的所有表。在这里,你已经在数据集中只传递一个表。你必须通过所有的表,包括报表的表。搜索结果
我如果您使用报表,然后使用数据源连接的方法,建议你如果不是断开数据源(report.SetDataSource())。在连接数据源必须显示报告之前设置的登录信息。结果

 私人无效PrintReport()
    {        报告的ReportDocument =新的ReportDocument();
        report.Load(ReportPath);        ConnectionInfo crConnectionInfo =新ConnectionInfo();
        crConnectionInfo.ServerName =HPL-WTS
        crConnectionInfo.DatabaseName =Enterprise32;
        crConnectionInfo.UserID =SA;
        crConnectionInfo.Password =*********;
        TableLogOnInfo crTableLogoninfo =新TableLogOnInfo();        的foreach(CrystalDecisions.CrystalReports.Engine.Table CrTable在report.Database.Tables)
        {
            crTableLogoninfo = CrTable.LogOnInfo;
            crTableLogoninfo.ConnectionInfo = crConnectionInfo;
            CrTable.ApplyLogOnInfo(crTableLogoninfo);
        }
        的foreach(在report.Subreports的ReportDocument报表)
        {
            的foreach(CrystalDecisions.CrystalReports.Engine.Table CrTable在subreport.Database.Tables)
            {
                crTableLogoninfo = CrTable.LogOnInfo;
                crTableLogoninfo.ConnectionInfo = crConnectionInfo;
                CrTable.ApplyLogOnInfo(crTableLogoninfo);
            }
        }        CrystalReportViewer1.ReportSource =报告;        CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
    }

如果你想使用断开数据源,即使你还没有列入报表,那么你可以使用一个命令,而不是多个表。这将使容易,提供更好的性能。监守你只需要只有一个表传递到的setDataSource方法。但是,不要忘了设置的tablename DataTable中报告,否则将不显示。

I currently have a crystal report embedded in a visual studio website. I deploy the website and install it on an IIS, and provide a link to the user so they can access globally and see this report. This system has been working great.

However, when I embedded a crystal report that has a sub report, the credentials are not being passed to the sub-report automatically. When i debug the solution, the initial report opens fine, when I click the item to open the sub-report, crystal report viewer asks me for database login credentials.

How can i pass those credentials automatically in the code so that users dont have to enter the code when viewing in the crystal report viewer.

Below is the code i use in my default.aspx.cs page. It contains the connection strings.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

namespace CFIBInventory
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection("Data Source=HPL-WTS;Initial Catalog=Enterprise32;Persist Security Info=True;User ID=sa;Password=********");
            DataSet1 ds = new DataSet1();
            SqlDataAdapter adapter = new SqlDataAdapter("SELECT     dbo.Material.MaterialCode, dbo.Material.CategoryCode, dbo.Material.Description, dbo.MaterialOnHand.LocationCode, dbo.Material.ValuationMethod,                       dbo.MaterialOnHand.Quantity FROM         dbo.Material INNER JOIN                      dbo.MaterialOnHand ON dbo.Material.MaterialCode = dbo.MaterialOnHand.MaterialCode WHERE     (dbo.Material.CategoryCode = 'CFIB3') AND (dbo.Material.ValuationMethod = 1) AND (dbo.Material.InactiveFlag = 0)", con);

            adapter.Fill(ds.cfibInventory);
            CrystalReport1 report = new CrystalReport1();
            report.SetDataSource(ds);
            CrystalReportViewer1.ReportSource = report;

            CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
        }
    }
}

The crystal report viewer is embedded into my .aspx page via the code below:

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="CFIBInventory._Default" %>

<%@ Register assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" namespace="CrystalDecisions.Web" tagprefix="CR" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <p>
    </p>
    <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" 
        AutoDataBind="true" />
</asp:Content>

The query for the sub report is in the sub-reports' database expert.

By the way, the database is connecting to a windows server 2005 machine. I do not believe it has public access setup, such as its own IIS. The previous reports, that do not have subreports, are installed on a newer 2012 Server as thats where the database is. Not sure if the machine has anything to do with the additional login prompt in crystal report viewer.

Any help will be great. Thank you in advance!


EDIT: After implementing solution from Nimesh

Well i added the connected connection type however, visual studio is underlining 'report' saying: Cannot use local variable 'report' before it is declared.

foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in report.Database.Tables)

and

foreach (ReportDocument subreport in report.Subreports)

I noticed i declare report later below as new crystalreport1. So I move that declaration above Nimesh code block and the red underline for 'report' goes away, but then all 6 instances of 'crtableLogoninfo' get underlined in red with the error: The name 'crtableLogoninfo' does not exist in the current context'

Any further help will be greatly appreciated.

Below is how my code looks now:

 using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data.SqlClient;
    using CrystalDecisions.Shared;
    using CrystalDecisions.CrystalReports.Engine;

    namespace CFIBInventory
    {
        public partial class _Default : System.Web.UI.Page
        {


            protected void Page_Load(object sender, EventArgs e)
            {



                //Nimesh code
                ConnectionInfo crConnectionInfo = new ConnectionInfo();
                crConnectionInfo.ServerName = "HPL-WTS";
                crConnectionInfo.DatabaseName = "Enterprise32";
                crConnectionInfo.UserID = "sa";
                crConnectionInfo.Password = "*********";

                foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in report.Database.Tables)
                {
                    crTableLogoninfo = CrTable.LogOnInfo;
                    crtableLogoninfo.ConnectionInfo = crConnectionInfo;
                    CrTable.ApplyLogOnInfo(crtableLogoninfo);
                }
                foreach (ReportDocument subreport in report.Subreports)
                {
                    foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in subreport.Database.Tables)
                    {
                        crtableLogoninfo = CrTable.LogOnInfo;
                        crtableLogoninfo.ConnectionInfo = crConnectionInfo;
                        CrTable.ApplyLogOnInfo(crtableLogoninfo);
                    }
                } // nimesh code end

                //Old connection string, i assume this shouldnt be here since nimesh code is for connecting
                //SqlConnection con = new SqlConnection("Data Source=HPL-WTS;Initial Catalog=Enterprise32;Persist Security Info=True;User ID=sa;Password=123qwerTy987");

                DataSet1 ds = new DataSet1();
                SqlDataAdapter adapter = new SqlDataAdapter("SELECT     dbo.Material.MaterialCode, dbo.Material.CategoryCode, dbo.Material.Description, dbo.MaterialOnHand.LocationCode, dbo.Material.ValuationMethod,                       dbo.MaterialOnHand.Quantity FROM         dbo.Material INNER JOIN                      dbo.MaterialOnHand ON dbo.Material.MaterialCode = dbo.MaterialOnHand.MaterialCode WHERE     (dbo.Material.CategoryCode = 'CFIB3') AND (dbo.Material.ValuationMethod = 1) AND (dbo.Material.InactiveFlag = 0)", con);

                adapter.Fill(ds.cfibInventory);

                CrystalReport1 report = new CrystalReport1();

                 // OLD CODE
                //report.SetDataSource(ds);
                CrystalReportViewer1.ReportSource = report;

                CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
            }
        }
    }

解决方案

The problem is in Crystal Report login info. before showing the report you have to set login info to all tables which are included in main report and their sub reports. You are using Disconnected Datasource Report Show method. so you don't need to provide login info to report document. your problem is here.

report.SetDataSource(ds);

when you are using SetDataSource method it is necessary to provide all tables which are included in crystal report document. here, you have passed only a single table in dataset. you must pass all tables including subreport tables.

I am suggesting you if you are using subreport then use connected datasource method instead if disconnected datasource(report.SetDataSource()). in Connected datasource you have to set login info before showing the report.

private void PrintReport()
    {

        ReportDocument report = new ReportDocument();
        report.Load("ReportPath");

        ConnectionInfo crConnectionInfo = new ConnectionInfo();
        crConnectionInfo.ServerName = "HPL-WTS";
        crConnectionInfo.DatabaseName = "Enterprise32";
        crConnectionInfo.UserID = "sa";
        crConnectionInfo.Password = "*********";
        TableLogOnInfo crTableLogoninfo = new TableLogOnInfo();

        foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in report.Database.Tables)
        {
            crTableLogoninfo = CrTable.LogOnInfo;
            crTableLogoninfo.ConnectionInfo = crConnectionInfo;
            CrTable.ApplyLogOnInfo(crTableLogoninfo);
        }
        foreach (ReportDocument subreport in report.Subreports)
        {
            foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in subreport.Database.Tables)
            {
                crTableLogoninfo = CrTable.LogOnInfo;
                crTableLogoninfo.ConnectionInfo = crConnectionInfo;
                CrTable.ApplyLogOnInfo(crTableLogoninfo);
            }
        }                         

        CrystalReportViewer1.ReportSource = report;

        CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
    }

if you want to use disconnected datasource even you have not included subreport then you can use a single command instead of multiple tables. that will make easy and gives better performance. becuase you just need to pass only a single table into SetDataSource method. but, dont forget to set tablename in DataTable otherwise report will not be displayed.

这篇关于如何从询问登录凭据打开报表时停止Crystal报表查看器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆