Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subreports loosing linkage when database name changes in execution

Status
Not open for further replies.

howler422

Programmer
Sep 28, 2007
1
US
We use three databases to manage project deployment, Dev, Migration and Production. The Dev and Production databases are named the same and exist on different servers. The Migration database is named differently because it resides on the same server as the Production database. This configuration has caused problems throughout our development process when using Crystal Reports.

I am developing windows forms applications in Visual Studio 2005, .Net framework 2.0 and I am using the Crystal Reports Designer provided in VS 2005. I have created reports that work on all three databases. However, I now have a report that has three subreports and when I try to run this report on the Migration database It prompts me for the parameters for the subreports.

The subreport is linked to the input parameter from the primary report.

Experiences:
When I run the report on the Dev database it runs fine. When I run it on Migration I get exceptions when I try to set parameters that are specific to the subreports and I am prompted for the parameters when I show the report.

I have changed my code to set the connection iformation on the primary and sub reports using the instructions in the VS2005 Walkthrough documentation from Beusiness Objects and I find myself here.

I am not embedding the reports in my application I am loading them from a location on a server.

It appears that the subreports are not getting their connection information updated. When I trace the execution the subreports appear to have the correct connection data so I'm not sure why I can't set the parameters and they are not supplied even if they are linked.

Here is the code I am using to call these reports.

public void printJobTicket(OMProduct prod, OMComponent comp)
{
// Create report

this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
try
{
ReportDocument myReport = new ReportDocument();
StringBuilder reportName = new StringBuilder();

// Build our report name from config based on DB target
reportName.Append (System.Configuration.ConfigurationManager.AppSettings.Get("ReportPath") + @"\");
reportName.Append("InitialFamilyPart.rpt");
myReport.Load(reportName.ToString());

myReport.PrintOptions.PaperSize = PaperSize.PaperLetter;
myReport.PrintOptions.PaperOrientation = PaperOrientation.Portrait;
PageMargins margins = new PageMargins(360, 400, 360, 360);
myReport.PrintOptions.ApplyPageMargins(margins);

ConnectionInfo crConnectionInfo = new
ConnectionInfo();

crConnectionInfo.ServerName = System.Configuration.ConfigurationManager.AppSettings.Get("ReportServer");
crConnectionInfo.DatabaseName = System.Configuration.ConfigurationManager.AppSettings.Get("ReportDatabase").Trim();
crConnectionInfo.UserID = System.Configuration.ConfigurationManager.AppSettings.Get("ReportUser").Trim();
crConnectionInfo.Password = System.Configuration.ConfigurationManager.AppSettings.Get("ReportPassword").Trim();

SetDBLogonForReport(crConnectionInfo, myReport);
SetDBLogonForSubreports(crConnectionInfo, myReport);


// setup parameters
ParameterValues rptparams = new ParameterValues();

ParameterDiscreteValue contractparam = new ParameterDiscreteValue();
ParameterDiscreteValue productparam = new ParameterDiscreteValue();
ParameterDiscreteValue compparam = new ParameterDiscreteValue();
ParameterDiscreteValue AssocIDparam = new ParameterDiscreteValue();
ParameterDiscreteValue AssocTypeparam = new ParameterDiscreteValue();

contractparam.Value = contract.ContractNumber;
rptparams.Add(contractparam);
myReport.DataDefinition.ParameterFields["@in_ContractNumber"].ApplyCurrentValues(rptparams);
rptparams.Clear();

productparam.Value = prod.ProductID;
rptparams.Add(productparam);
myReport.DataDefinition.ParameterFields["@in_ProductID"].ApplyCurrentValues(rptparams);
rptparams.Clear();

compparam.Value = comp.ComponentID;
rptparams.Add(compparam);
myReport.DataDefinition.ParameterFields["@in_ComponentID"].ApplyCurrentValues(rptparams);
rptparams.Clear();

try
{
AssocIDparam.Value = comp.ComponentID;
rptparams.Add(AssocIDparam);
myReport.DataDefinition.ParameterFields["@in_AssociateID"].ApplyCurrentValues(rptparams);
rptparams.Clear();

AssocTypeparam.Value = this.AssocTypes.Item("Component").AssociateTypeID;
rptparams.Add(AssocTypeparam);
myReport.DataDefinition.ParameterFields["@in_AssociateTypeID"].ApplyCurrentValues(rptparams);
rptparams.Clear();
}
catch (Exception ex)
{
}

// Load Form
frmReportView myReportView = new frmReportView();
myReportView.MdiParent = this.ParentForm;
myReportView.Show();
myReportView.Report = myReport;
}
catch (Exception ex)
{
MessageBox.Show("Report did not generate,\n" + ex.Message, "Exception:", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
this.Cursor = System.Windows.Forms.Cursors.Default;
}
}

private void SetDBLogonForReport(ConnectionInfo connectionInfo, ReportDocument reportDocument)
{
Tables tables = reportDocument.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
{
TableLogOnInfo tableLogonInfo = table.LogOnInfo;
tableLogonInfo.ConnectionInfo = connectionInfo;
tableLogonInfo.TableName = table.Name;
// Added to try and make other databases work.
table.ApplyLogOnInfo(tableLogonInfo);
table.Location = table.Name;
}
}

private void SetDBLogonForSubreports(ConnectionInfo connectionInfo, ReportDocument reportDocument)
{
Sections sections = reportDocument.ReportDefinition.Sections;

foreach (Section section in sections)
{
ReportObjects reportObjects = section.ReportObjects;
foreach (ReportObject reportObject in reportObjects)
{
if (reportObject.Kind == ReportObjectKind.SubreportObject)
{
SubreportObject subreportObject = (SubreportObject)reportObject;
ReportDocument subreportDocument = subreportObject.OpenSubreport(subreportObject.SubreportName);
SetDBLogonForReport(connectionInfo, subreportDocument);
}
}
}
}

These reports are the primary target of our current development. Without them we can not deploy. We can not test them currently so we can not verify they will work in production. I need to resolve this so we can depoloy this application.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top