Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
saurabh_pathak
Active Contributor

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:

  1. Open the report.
  2. Go to Database> Set DataSource Loaction
  3. Choose Current Data Source > Database.
  4. Expand the properties of the Database as well as the Table

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:

  1. CrystalDecisions.CrystalReports.Engine
  2. CrystalDecisions.ReportAppServer.ClientDoc
  3. CrystalDecisions.ReportAppServer.Controllers
  4. CrystalDecisions.ReportAppServer.DataDefModel

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.

Additional Reference:

  1. Crystal Reports .NET SDK API Reference
  2. Report Application Server Database Connectivity
Labels in this area