Skip to Content
avatar image
Former Member

Dynamic Parameter in C#

Hello and thank you

I am using SAP BusinessObjects Crystal Reports 2013 Support Pack 1


CR Developer

on a 64-Bit Windows 7 operating system

with Microsoft Visual Studio 2010 Professional

     target framework = .NET Framework 4.0

I went to and dowloaded the free trial for crystal reports.

I made a report.

then after a few weeks getting the hang of how to use SAP i started trying to develop SAP reports with visual studio using C#.

I made a basic report and on my machine the report works fine.

However people who do not have crystal reports on their machines cannot run the program I created.

So i went back to and i downloaded the:

SAP Crystal Reports, developer version for Microsoft Visual Studio - Click Once (64 Bit)

The program I wrote is very simple.

using CrystalDecisions.CrystalReports.Engine;

using CrystalDecisions.Shared;

using System.Data.SqlClient;

using CrystalDecisions.ReportSource;

CrystalDecisions.Windows.Forms.CrystalReportViewer CrystalReportViewer2 = new CrystalDecisions.Windows.Forms.CrystalReportViewer();

CrystalReportViewer2.ActiveViewIndex = -1;

CrystalReportViewer2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;

CrystalReportViewer2.CachedPageNumberPerDoc = 10;

CrystalReportViewer2.Cursor = System.Windows.Forms.Cursors.Default;

CrystalReportViewer2.Dock = System.Windows.Forms.DockStyle.Fill;

CrystalReportViewer2.Location = new System.Drawing.Point(0, 0);

CrystalReportViewer2.Name = "CrystalReportViewer2";

CrystalReportViewer2.Size = new System.Drawing.Size(802, 451);

CrystalReportViewer2.TabIndex = 0;


CrystalDecisions.CrystalReports.Engine.ReportDocument crReportDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

crReportDocument.Load("J:\\Loans\\Darryn\\CrystalReports\\Credit Memo1.rpt");

when the report has no dynamic parameter i can view the report on another machine just fine. 

on my developer machine everything works fine all the time.

however on another machine which only has the link installed on it i get the following problem.

also if i put the dynamic parameter into the crystal report itself through the crystal report environment (not through visual studio)

i hit the dynamic parameter button and instead of saying what it wants me to set the parameter equal to i get it asking me to enter my database credentials.  however when i do nothing happens when i click ok.

Untitled.png (26.8 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    Sep 11, 2014 at 10:42 PM

    Hello Jones,

    You can set the database credentials in c# code part like this way:  For ex:

    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;



    You can run any system never ask any db credentials.

    One more way to go for this:

    You can set the database credentials in web.config file also but you are working on other machine compulsary paste the same web.config file in that machine...

    For more details see KBA 1876642 for populate dynamic parameters in c# when report is loaded.



    Add comment
    10|10000 characters needed characters exceeded

    • Well UDL is just another way to check if a connection can be established to the database - with no CR involved. E.g.; a UDL is not a CR construct. And if the UDL fails, then we are back to my post from Sept. 12.

      - Ludek