cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Parameter in C#

Former Member
0 Kudos

Hello and thank you

I am using SAP BusinessObjects Crystal Reports 2013 Support Pack 1

Version 14.1.1.1036

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 sap.com 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 SAP.com 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;

Controls.Add(CrystalReportViewer2);

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.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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;

  CrTable.ApplyLogOnInfo(crtableLogoninfo);

  }

  crystalReportViewer1.ReportSource = cryRpt;

  crystalReportViewer1.Refresh();

  }

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.

Thanks,

DJ

Former Member
0 Kudos

Ok my developer machine has SAP, Microsoft SQL server 2008, and visual Studio 2010 professional

my second machine (users machine) has none of those installed on it.  the user has

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

installed on their machine. 

1. if i run the program (on the developer machine) without the code you gave me and I refresh the report inside the visual studio CR viewer at the program runtime it pops this up:

notice on how the second machine the name of the database is blanked out but on the developer machine it is not.

If i add the code you provided then on the developer machine i can refresh the document without requiring a password. However on my user's machine they still have the same problem when they refresh the document:

Notice again how it pops up the same log in screen as on the developer machine but this time there is no database entry, nor does it allow you to enter a database name thus it always throws a log in error.

2. Now if I were to add a dynamic parameter to the SAP document itself through the Crystal Reports document.  Then in my code refer to that parameter with the following line of code:

crReportDocument.SetParameterValue("Account Number", ID);

then on my development machine it runs great, exactly the way I want.

But on my user's machine there seems to be some sort of database connection issue. because i have a problem look different output:

So when on both machines when I click on the parameter button I get a new window.

On the developer machine i get the correct window asking what the parameter should be.

but on the user machine instead it asks me to connect to the database.  but when i do put in the password and click ok.  it doesn't connect instead it just takes out the password and brings up the same screen. 

So in summary, there seems to be some problem when the user's machine tries to connect to the database.  I am not using a browser or network connection.  There is no ASP.NET setup or assembly files.  My user's are just running a visual studio program build executable that is created when i click build solution in the VS environment.  I think there must be some part of the distribution package that I am missing or something.  because before i installed that package on the users machine they couldn't even get anything at all related to SAP viewed on their machine.

thank you.

former_member183750
Active Contributor
0 Kudos

As you are using MS SQL 2008, make sure that the runtime is using SQL Native 10 client to connect to the database.

- Ludek

Senior Support Engineer AGS Product Support, Global Support Center Canada

Follow us on Twitter

Former Member
0 Kudos

Yes, I did Create New Connection -> OLE DB (ADO) -> SQL Server Native Client 10.0

former_member183750
Active Contributor
0 Kudos

There is more than one issue here;

If you use:

crReportDocument.SetParameterValue("Account Number", ID);

The there should be no parameter screen displayed on your dev computer or any other computer at all.

The screenshot of the prompts from the runtime computer is very weird and indicates a viewer configuration issue.

I am dubious that we'll be able to resolve this on these forums and I'd recommend creating a phone case here:

Crystal Single Case Technical Support - SAP Business Objects US Online Store | SAP Online Store

- Ludek

Former Member
0 Kudos

How can I know that if I pay the $200 my issue will get resolved?

former_member183750
Active Contributor
0 Kudos

I can only tell you that if it does not get resolved, the incident will be refunded. If it is a bug, it will be tracked (hopefully resolved) and again the incident will be refunded.

Oh. there is an interesting conversation re. parameters going on here:

Perhaps something worth following.

- Ludek

Former Member
0 Kudos

Dear Ludek:

I was talking with a coworker about my issue.  It has to be something basic with what I installed on the user machine.  When I tried running my program on a machine which had nothing from SAP installed on it, the program kept crashing.  Then we went to SAP.com and had our IT guy put that SAP Crystal Reports, developer version for Microsoft Visual Studio - Click Once (64 Bit)

and the users could view the report.  but anytime they try to refresh the report it asks them to connect to the db.  However, there is one problem with them trying to connect to the db, the slot for "database" is disabled and it is blanked out.  so no matter what there is a login error. the code has connection info for the database in it so I don't understand why they are being asked to log in to the database in the first place. 

What my thought is, there must be something we forgot to download and it needs that to run correctly.  why is it that it runs fine on my machine but on another machine that does not have the same download as me it doesnt run?

Former Member
0 Kudos

There definitely something about not having the entire crystal reports package.  I just had one of the IT guys install the crystal reports viewer on the user machine.  It didn't solve my problem.  But I can tell there is something going on because the developer machine has the full blown crystal reports environment and when i open a file on the dynamic parameter kicks in.  When I open the report on the user machine and view it with just the crystal reports viewer, it does not activate the dynamic parameter.  Nor does it allow me to refresh the report.  it shows there IS a dynamic parameter but I cannot change it or set it equal to anything. 

My case in point is that there must be some setting that I am forgetting or some link that I still need to download to make it work.  because it has the ability to be working properly.  Why do I need to download the entire crystal reports package on every single machine at my work?

former_member183750
Active Contributor
0 Kudos

Only thing I can think of is having a look at the link below that explains how the CR viewer should be configured on the server:

Visual Studio 2012 Crystal Report not working on Windows Server 2012/ 0x800a1391 – JavaScr...

The parameter screen you are getting on that server is way too bizarre...

- Ludek

Former Member
0 Kudos

im leaving work now.  Ill take a look at that link when i get home because my work pc's access to that link is blocked. 

I found a forum that you had posted on a few years ago.  this guy seemed to be having the same problem as me.

Crystal Reports for VS2010 - Login not picking up the database name.

He was helped by a guy named David Hilton.  In david's suggestions, david had suggested to check if the user machine was able to connect to the database by making a .udl file.  So the developer machine can make the .udl file fine, however the user machine cannot.  I think there in lies the problem. 

former_member183750
Active Contributor
0 Kudos

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

Answers (0)