cancel
Showing results for 
Search instead for 
Did you mean: 

open subreport database connection

Former Member
0 Kudos

I have some CR 8.5 reports with subreport. I used to have codes to open the subreport database connection.

Set crSecs = Report.Sections

For i = 1 To crSecs.Count

Set crSec = crSecs.Item(i)

Set crRepObjs = crSec.ReportObjects

For x = 1 To crRepObjs.Count

If crRepObjs.Item(x).Kind = crSubreportObject Then

Set crSubReport = Report.OpenSubreport(crRepObjs.Item(x).SubreportName)

'the following code sets the subreport table to a different database

crSubReport.Database.Tables(1).SetLogOnInfo DataSource, strPUser, strPass

End If

Next

Next

Now I am using CR 11 and the code no longer works. My subreport doesn't refresh the data according to the database I used.

Any suggestion will be greatly appreciated.

Thanks

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Thanks a lot. It works great.

Former Member
0 Kudos

Shweta

Thank you and I will try the code. One quick question do you know if we can still use CRAXDRT? I am using CR Viewer. I tried all the reference and component I can think of and I still can't use CRAXDRT in CR 11.

Thanks

former_member292966
Active Contributor
0 Kudos

Hi,

SetLogonInfo works in XI. I've used it. You need to make sure you set it for each of the tables in your subreport.

Thanks,

Brian

Former Member
0 Kudos

Hi Yongling,

Have a look to :

[Sample Codes|https://boc.sdn.sap.com/codesamples] and [SDK Library|https://www.sdn.sap.com/irj/sdn/businessobjects-sdklibrary]

Hope this helps!!

Regards,

Shweta

Former Member
0 Kudos

Hi Yongling,

We need to pass database logon code for both Main report and Subreport


/*Database Logon for the main report*/
ConnectionInfo crConnectionInfo = new ConnectionInfo();

crConnectionInfo.ServerName = "SERVER";
crConnectionInfo.DatabaseName = "DATABASE";
crConnectionInfo.UserID = "USERID";
crConnectionInfo.Password = "PASSWORD";

// Use a loop to go through all the tables in the main report
foreach(Table crTable in crReportDocument.Database.Tables)
{
// Get the TableLogOnInfo from the Table and then set the new
// ConnectionInfo values.
TableLogOnInfo crLogOnInfo = crTable.LogOnInfo;
crLogOnInfo.ConnectionInfo = crConnectionInfo;

// Apply the TableLogOnInfo
crTable.ApplyLogOnInfo(crLogOnInfo);
// Set the location of the database. This value will vary from // database to database.
crTable.Location = "DATABASE.OWNER.TABLENAME";
}
/*Database Logon for a subreport*/
ConnectionInfo crConnectionInfo = new ConnectionInfo();

crConnectionInfo.ServerName = "SERVER";
crConnectionInfo.DatabaseName = "DATABASE";
crConnectionInfo.UserID = "USERID";
crConnectionInfo.Password = "PASSWORD";

// Loop through the ReportObjects in a report and find all the subreports
foreach(ReportObject crReportObject in crReportDocument.ReportDefinition.ReportObjects)
{
// Check the kind of the ReportObject, if it is a subreport 
// proceed. If not skip.
if(crReportObject.Kind == ReportObjectKind.SubreportObject)
{
// Get the SubReport in the form of a ReportDocument
string sSubreportName = ((SubreportObject)crReportObject).SubreportName;
ReportDocument crSubReportDocument = crReportDocument.OpenSubreport(sSubreportName);
// Use a loop to go through all the tables in the main report
foreach(Table crTable in crSubReportDocument.Database.Tables)
{
// Get the TableLogOnInfo from the Table and then set the new
// ConnectionInfo values.
TableLogOnInfo crLogOnInfo = crTable.LogOnInfo;
crLogOnInfo.ConnectionInfo = crConnectionInfo;

// Apply the TableLogOnInfo
crTable.ApplyLogOnInfo(crLogOnInfo);

// Set the location of the database. This value will vary from database to 
// database.
crTable.Location = "DATABASE.OWNER.TABLENAME";
}
} 
}

Hope this helps!!

Regards,

Shweta