ASP.NET - avoiding login prompt for crystal report

Asked By Ashokkumar S on 17-Jul-11 06:44 AM

my connection string is constr

my servername is

my database is ttmast

my userid is ******

mypassword is ******

please help me in create a crystal report .

when i create a crystal report each time it asks for login prompt please help me to avoid the login prompt

Devil Scorpio replied to Ashokkumar S on 17-Jul-11 08:48 AM
Hi Ashok,

you can avoid it by passing dynamic Login Paramater details to Crystal report at runtime.
The Given article enable you to how to pass the logon information like Server Name , database Name , User Name and password dynamically to the Crystal Reports from C# applications.

Please refer the following website for more details
Reena Jain replied to Ashokkumar S on 17-Jul-11 11:24 AM

To solve this problem You will have to provide the login information programmatically so that your report page don’t prompt for it. To solve the problem you will have to done the following. Add the following code to the top of the report page.

using CrystalDecisions;
using CrystalDecisions.CrystalReports;
using CrystalDecisions.Shared;
ReportDocument rpt = new ReportDocument();
rpt.SetDatabaseLogon("myUserLogin", "mypassword", @"Server", "Database");
CrystalReportViewer1.ReportSource = rpt;

Hope this will help you
Riley K replied to Ashokkumar S on 17-Jul-11 11:51 AM


Set the logon information in you code as shown below. Use this code approach instead.

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

public partial class _Default : System.Web.UI.Page 
    private ReportDocument rpt;

    private void Page_Init(object sender, EventArgs e)
    protected void Page_Load(object sender, EventArgs e)

    private void ConfigureCrystalReports()
      rpt= new ReportDocument();
      string reportPath = Server.MapPath("youreportname.rpt");
      ConnectionInfo connectionInfo = new ConnectionInfo();
      connectionInfo.DatabaseName = "Northwind";
      connectionInfo.UserID = "user";
      CrystalReportViewer1.ReportSource = rpt;
    private void SetDBLogonForReport(ConnectionInfo connectionInfo, ReportDocument reportDocument)
      Tables tables = reportDocument.Database.Tables;
      foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
        TableLogOnInfo tableLogonInfo = table.LogOnInfo;
        tableLogonInfo.ConnectionInfo = connectionInfo;

Jitendra Faye replied to Ashokkumar S on 18-Jul-11 12:01 AM
The following Code describes how to pass the logon information like Server Name , database Name , User Name and password dynamically to the Crystal Reports from C# applications.

Use this code-

using System;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

namespace WindowsApplication1
    public partial class Form1 : Form
        public Form1()

        private void button1_Click(object sender, EventArgs e)
            ReportDocument cryRpt = new ReportDocument();
            TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
            TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
            ConnectionInfo crConnectionInfo = new ConnectionInfo();
            Tables CrTables ;

            cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt");

            crConnectionInfo.ServerName = "YOUR SERVER NAME";
            crConnectionInfo.DatabaseName = "YOUR DATABASE NAME";
            crConnectionInfo.UserID = "YOUR DATABASE USERNAME";
            crConnectionInfo.Password = "YOUR DATABASE PASSWORD";

            CrTables = cryRpt.Database.Tables ;
            foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
                crtableLogoninfo = CrTable.LogOnInfo;
                crtableLogoninfo.ConnectionInfo = crConnectionInfo;

            crystalReportViewer1.ReportSource = cryRpt;

Try this code and let me know.