How to stop crystal report viewer from asking login credentials when opening subreport

久未见 提交于 2019-11-27 05:35:45

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.

Shanti Lal Namchuriya

Try this
open Field Explorer ---> right click on Database Field ---> Current Data Source ---> Report Connection ---> Report ---> Property ---> Set Property as ---

Data Source: .\Databasename.accdb

and code on viewer form load as

Dim cryRpt As New ReportDocument
Dim Report1 As New rptItemWise
Dim strServerName As String
strServerName = Application.StartupPath
rptItemWise.SetDatabaseLogon("admin", "", strServerName, "dastabasename.accdb", True)
cryRpt.Load(Application.StartupPath + "\rptItemWise.rpt")

Also change the report connection same as data source. I think that code will work for you.

my solution was by installing SQL Server 2012 Client Tool Connectivity, and backward client connectivity components using SQL Server setup source.

I had this error with subreports too. Important: my report designer used only one table in 'main' report and one (different) table in subreport. My solution:

Dim ds as DataSet
'... Put your code to fectch data
report.SetDataSource(ds)

Dim ds1 as DataSet
'... Put your code to fetch data
Dim dtb = ds1.Tables(0)
dtb.TableName = "Same_name_used_in_report_designer"
report.Subreports(0).SetDataSource(dtb)

Two important things here:

  1. Report's datasource must be DataSet with only 1 DataTable.
  2. Subreport's datasource must be a DataTable, not full DataSet.

I don't fully understand Crystal Reports foundations so I can't explain why, but it solved my problem.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!