Sometimes we just want to know the database that is being used by Crystal Reports and its properties. It’s tedious to go back to designer and check every report in it. How would it be if we do that using .NET SDK?
We are familiar with the ReporDocument Object Model, but to achieve this we have to leverage the ReportClientDocument Object Model. These two models can be used interchangeably to manipulate a report.
If we are to find the properties from the designer then:
As far as this task is concerned we have to use to inProc RAS where inProc stands for In-Process and it means that the deployment package for the RAS .NET application requires only the .NET assemblies. Does definition look complicated? Here is the simpler version. inProc RAS has the ability to create/ manipulate the report definition/template without requiring any enterprise products like BOE, Crystal Server etc….
The references that you would require for creating the .NET project are following:
Following code can help you achieve the objective:
Sample Code |
---|
ReportDocument rd = new ReportDocument(); rd.Load(Server.MapPath("CrystalReports.rpt")); ISCDReportClientDocument rcd = rd.ReportClientDocument; DatabaseController databaseController = rcd.DatabaseController; CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo connectionInfo = databaseController.FindConnectionInfoByDBServerName("DatabaseName"); PropertyBag oldPb = connectionInfo.Attributes; foreach (String attribute in oldPb.PropertyIDs) { if (oldPb[attribute].ToString().Equals("System.__ComObject")) { Response.Write(attribute + " (" + oldPb[attribute].GetType().ToString() + ") = "); PropertyBag oldLogonPb = (PropertyBag)oldPb[attribute]; foreach (String logonAttribute in oldLogonPb.PropertyIDs) { Response.Write(logonAttribute + " = " + oldLogonPb[logonAttribute].ToString() + " (" + oldLogonPb[logonAttribute].GetType().ToString() + ")"); } } else { Response.Write(attribute + " = " + oldPb[attribute].ToString() + " (" + oldPb[attribute].GetType().ToString() + ")"); } } CrystalDecisions.ReportAppServer.DataDefModel.Tables tables = databaseController.Database.Tables; CrystalDecisions.ReportAppServer.DataDefModel.Table customerTable = (CrystalDecisions.ReportAppServer.DataDefModel.Table)tables.FindTableByAlias("Sales_by_Category"); Response.Write("Owner" + " = " + customerTable.QualifiedName + " "); |
This code works for Crystal Reports 2008 (12.x) and Crystal Reports for Visual Studio 2010 (13.x) without any problem.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
37 | |
10 | |
7 | |
5 | |
5 | |
5 | |
4 | |
4 | |
3 | |
3 |