0
try
{
     string spath = AppDomain.CurrentDomain.BaseDirectory;
     spath += "myReportFileName.rpt";

     ReportDocument cryRpt = new ReportDocument();
     cryRpt.Load(spath);

     cryRpt.DataSourceConnections[0].SetConnection("Server Name", "DB Name", true);
     cryRpt.DataSourceConnections[0].IntegratedSecurity = true;
     cryRpt.SetParameterValue("Field Name", "Value");
     cryRpt.RecordSelectionFormula = "Correct Formula";

     crystalReportViewer1.ReportSource = cryRpt;
     crystalReportViewer1.Refresh();
}
catch (System.Exception ex)
{
     MessageBox.Show("Error: " + ex.Message);
}

In my system, this code is ok. But in other system, It has error. I installed in all other systems crystal report correctly.

This code was executing with error:

crystaldecisions.crystalreports.engine.reportdocument' threw an exception

Then I executed CRRuntime_32bit_13_0_3.msi in client system. That error solved But other problem:

After to run code, the "Database Login" dialog is showing, and I don't connect to database automatically, and don't view the report file!!!

Please help me, what do I have to do?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
nabegheh95
  • 195
  • 3
  • 19
  • If you're using integrated security the user that executes your report needs to have permission on the database. If the authentication fails, the user is presented with the connection dialog to provide the correct credentials. There is nothing to fix in your code. – rene Jan 28 '17 at 09:19
  • the user has prmission, and the "Database login" dialog is shown with disable database name field!!! then use cann't set database name – nabegheh95 Jan 28 '17 at 10:21
  • what is my solution? @rene – nabegheh95 Jan 28 '17 at 10:49
  • I have no idea. If you are sure the credentials are OK and other dependencies are in place i have no clue. – rene Jan 28 '17 at 10:51
  • @rene Thank you anyway – nabegheh95 Jan 28 '17 at 10:59
  • You have to login your crystal report itself in code behind before you show it. – Vijunav Vastivch Jan 30 '17 at 00:32

1 Answers1

0

I solved my problem. :) when I was creating the project , the crystalReport version 10 had was installed on my system. therefor I choosed "crystalReportViewer version 10" from Toolbox Item. I uninstalled version 10 of crystal report and installed version 11. In next step, I deleted crystalReportViewer from toolbox of visual studio then again choosed "crystalReportViewer version 11" from Toolbox Item.

now my project and created exe file, executes correctly in all systam that has crystall report vesion 10 later.

thank you! @rene :)

nabegheh95
  • 195
  • 3
  • 19