Click here to Skip to main content
15,911,306 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my code, but it still give me login Failed.already i set EnableDatabaseLogonPrompt="False" in Crystal Report Viewer


What I have tried:

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

namespace WebApplication1
{
    public partial class ReportViewer : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadReport();
            }
        }
        
        private void LoadReport()
        {
          
            string[] paths = { @"D:\CHAMINDA", "Project", "WebApplication", "WebApplication1", "WebApplication1", "SEC0001.rpt" };
            string fullPath = Path.Combine(paths);

            Session["ReportDocument"] = null;
            string rptName = fullPath;

            ReportDocument rptDoc = new ReportDocument();
            rptDoc.Load(rptName);
            Session["ReportDocument"] = rptDoc;

            ReportDocument cryRpt = (ReportDocument)Session["ReportDocument"];
            TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
            TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
            ConnectionInfo crConnectionInfo = new ConnectionInfo();
            Tables CrTables;
            
            try
            {
   
                cryRpt.Load(fullPath);
                cryRpt.DataSourceConnections[0].SetConnection(@".\192.168.4.41", "DMSSECURITY_WEB", true);
                cryRpt.DataSourceConnections[0].IntegratedSecurity = true;
                CrTables = cryRpt.Database.Tables;

                //crConnectionInfo.ServerName = "192.168.4.41";
                //crConnectionInfo.DatabaseName = "DMSSECURITY_WEB";
                //crConnectionInfo.UserID = "sa";
                //crConnectionInfo.Password = "#compaq123";
                //crConnectionInfo.IntegratedSecurity = true;
                //CrTables = cryRpt.Database.Tables;


                foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
                {
                    crtableLogoninfo = CrTable.LogOnInfo;
                    crtableLogoninfo.ConnectionInfo = crConnectionInfo;
                    CrTable.ApplyLogOnInfo(crtableLogoninfo);
                }
                CrystalReportViewer1.ReportSource = cryRpt;
                CrystalReportViewer1.RefreshReport();

            }
            catch (Exception ex)
            {

                throw ex;
            }
        }

    }
}
Posted
Updated 26-Nov-20 20:31pm

Maybe you can find more information here: Crystal Report Login Prompt[^]

It seems the good people at CodeProject are a bit tired of all those Crystal Report problems.
So if no one answers your question take a look at an alternative like FastReport,
see: open-source-reporting-tools[^]
 
Share this answer
 
v2
Provide login info for each datatable in crystal report

VB
With TblInfo.ConnectionInfo
            .ServerName = Utils.getConStr("Datasource")
            .DatabaseName = Utils.getConStr("DataBase")
            .UserID = Utils.getConStr("user")
            .Password = Utils.getConStr("pwd")
        End With

        With pReport
            .Database.Tables(0).SetDataSource(pDS.Tables(0))
            .Database.Tables(0).ApplyLogOnInfo(TblInfo)
            .RecordSelectionFormula = ""
            For i As Integer = 0 To pReport.Subreports.Count - 1
                If .Subreports(i).Database.Tables.Count > 0 Then
                    .Subreports(i).Database.Tables(0).ApplyLogOnInfo(TblInfo)
                    .Subreports(i).Database.Tables(0).SetDataSource(pDS.Tables(.Subreports(i).Database.Tables(0).Name))
                    '.Subreports(i).RecordSelectionFormula = ""
                End If
            Next
        End With
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900