Click here to Skip to main content
15,881,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i tried to load crystal report on windows server 2012 R2 from IIS i get the error
Failed to open the connection. MA723DT 2608_14160_{B2777DB7-D4BD-4E31-8748-7E70DE55C132}.rpt
but its working in same machine from visual studio when debug the application

What I have tried:

private void GetReport(string EmpID, string StartDate, string EndDate, string Conn, string Cmpid)
      {
          try {
              TableLogOnInfos TableLogOnInfos = new TableLogOnInfos();
              TableLogOnInfo TableLogOnInfo = new TableLogOnInfo();
              ConnectionInfo ConnectionInfo = new ConnectionInfo();
              SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
              Tables Tables;
              ReportDocument report = new ReportDocument();
              string FileName = "~/MA723BA.rpt";
              report.Load(Server.MapPath(FileName));
              if (Conn != "")
              {
                  string ConnString = ConfigurationManager.ConnectionStrings[Conn].ConnectionString;
                  if (ConnString.ToLower().StartsWith("metadata="))
                  {
                      System.Data.Entity.Core.EntityClient.EntityConnectionStringBuilder efBuilder = new System.Data.Entity.Core.EntityClient.EntityConnectionStringBuilder(ConnString);
                      ConnString = efBuilder.ProviderConnectionString;
                      builder.ConnectionString = ConnString;

                      ConnectionInfo.ServerName = builder.DataSource;
                      ConnectionInfo.DatabaseName = builder.InitialCatalog;
                      ConnectionInfo.UserID = builder.UserID;
                      ConnectionInfo.Password = builder.Password;
                      Tables = report.Database.Tables;

                      foreach (CrystalDecisions.CrystalReports.Engine.Table table in Tables)
                      {
                          TableLogOnInfo = table.LogOnInfo;
                          TableLogOnInfo.ConnectionInfo = ConnectionInfo;
                          table.ApplyLogOnInfo(TableLogOnInfo);
                      }

                  }
              }
              ParameterRangeValue myParameterRangeValue = new ParameterRangeValue();

              myParameterRangeValue.StartValue = StartDate;
              myParameterRangeValue.EndValue = EndDate;
              report.SetParameterValue(0, EmpID);

              report.SetParameterValue(1, myParameterRangeValue);
              CrystalReportViewer1.ReportSource = report;
              CrystalReportViewer1.DataBind();
          }
          catch(Exception er)
          {
              throw new Exception(er.ToString());
          }
          }
Posted
Updated 6-Jan-21 19:20pm
Comments
Richard Deeming 16-Apr-20 14:23pm    
catch(Exception er)
{
    throw new Exception(er.ToString());
}

Seriously, don't do that.

You've just thrown away any chance for the calling code to catch an exception it know how to handle. And you've destroyed any information in the exception which isn't included in its string representation.

If you really need to catch and rethrow an exception, just use:
catch (Exception ex)
{
    throw;
}

But since you're not doing anything with the exception, you might as well just remove the try..catch block and let exceptions propagate normally.
$ultaNn 16-Apr-20 14:51pm    
try catch removed

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900