Getsuyodev, Programming is mainly used when constructing an application. Programming requires knowledge of application domains, algorithms, and programming language expertise. Programming can be developed in different logic based on developer knowledge.

CSharp Crystal Reports Dynamic Logon parameters

The following section describes how to pass the login information like Server Name, Database Name, User Name and password dynamically to the Crystal Reports from C# applications.

When you new in Crystal Report, many time you get this message… Failed to open the connection. This is a common problem with embedding Crystal Reports in C#. The dynamic logon parameter passing will solve this issue.

When you run the previous programs in this C# tutorial, the Crystal Reports asks the Username and Password every time you run the Crystal Report. This section explains how to avoid the dialogue box asking username and password at runtime on Crystal Reports login. In this section we are passing User ID, Password, Server Name and Database Name dynamically to Crystal Reports from C#.

Select the default form (Form1.cs) you created in C# and drag a button and a CrystalReportViewer control to your form.

You have to include CrystalDecisions.CrystalReports.Engine in your C# Source Code.

using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

Copy and paste the following source code and run your C# project.

ConnectionInfo crConnectionInfo = new ConnectionInfo();
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;

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

The Crystal Reports file path in your C# project files location, there you can see CrystalReport1.rpt. So give the full pathname of Crystal Reports file like c:\projects\crystalreports\CrystalReport1.rpt

You have to replace the source code values of

crConnectionInfo.ServerName = “YOUR SERVER NAME”;

crConnectionInfo.DatabaseName = “YOUR DATABASE NAME”;

crConnectionInfo.UserID = “YOUR DATABASE USERNAME”;

crConnectionInfo.Password = “YOUR DATABASE PASSWORD”;

Comments are closed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More