如何修改Business Objects XI 3.1中Crystal报表的数据库配置属性

本文关键字:Crystal 报表 属性 配置 数据库 XI 何修改 修改 Objects Business | 更新日期: 2023-09-27 17:54:48

将报表上载到Business Objects XI 3.1时,可以使用中央管理控制台中的Database Configuration选项修改报表的默认属性。在此选项中,您可以选择使用报表中使用的数据源信息,也可以指定自定义数据源。

我正在尝试编写一个C#.NET Windows窗体,它将遍历指定文件夹/子文件夹中的所有报告,并更改默认用户ID和密码。这可能吗?如果是,有人能举个例子吗?

我通读了SDK,发现了ReportLogon类。。。这是我访问数据库配置属性所需要的吗?

谢谢。

如何修改Business Objects XI 3.1中Crystal报表的数据库配置属性

我正在处理同样的需求。我正在使用swing和BO SDK开发一个工具,用于更新批量Crystal报告连接。

下面是我的伪代码,我将使用它来更新连接。

示例:-

     package org.bukhantsov.javatool;
import com.businessobjects.rebean.wi.DocumentInstance;
import com.crystaldecisions.sdk.exception.SDKException;
import com.crystaldecisions.sdk.framework.CrystalEnterprise;
import com.crystaldecisions.sdk.framework.IEnterpriseSession;
import com.crystaldecisions.sdk.framework.ISessionMgr;
import com.crystaldecisions.sdk.occa.infostore.IInfoObject;
import com.crystaldecisions.sdk.occa.infostore.IInfoObjects;
import com.crystaldecisions.sdk.occa.infostore.IInfoStore;
import com.crystaldecisions.sdk.occa.report.application.ReportClientDocument; 
import com.crystaldecisions.sdk.occa.managedreports.reportAppFactory; 
import com.crystaldecisions.sdk.occa.report.application.databaseController;
import com.crystaldecisions.sdk.occa.report.data.IConnectionInfo;
import com.crystaldecisions.sdk.occa.report.document.*;
import com.crystaldecisions.sdk.occa.report.definition.*;
import com.crystaldecisions.sdk.occa.report.lib.propertyBag;
class ChangeDataSource {
    public static void main(String args[]){
       String cms = "134.X.X.X:6400";
       String username = "Administrator";
       String password = "";
       String auth = "secEnterprise";
       IEnterpriseSession enterpriseSession = null;
       ISessionMgr sessionMgr = null;//CrystalEnterprise.getSessionMgr();   
       Exception failure = null;
       boolean loggedIn = true;
       ReportClientDocument clientDoc = null;
       if (enterpriseSession == null)
       {
      try
      {
          sessionMgr = CrystalEnterprise.getSessionMgr();
          enterpriseSession = sessionMgr.logon(username, password, cms, auth);
          System.out.println("'nLOGIN SUCCESSFUL'n");
      }
      catch (Exception error)
      {
          loggedIn = false;
          failure = error;
      }
      if (!loggedIn)
      {
         System.out.println("'nLOGIN FAILED'n");
      }
      else
      {
          // Query for the sample report from the Enterprise CMS.
          try {
            IInfoStore iStore = (IInfoStore) enterpriseSession.getService("InfoStore");
            IInfoObjects infoObjects = iStore.query("Select SI_ID From CI_INFOOBJECTS Where SI_Type='CrystalReport'");
            System.out.println("'ninfoObjects size = "+infoObjects.getResultSize());
            IReportAppFactory reportAppFactory = (IReportAppFactory)enterpriseSession.getService("RASReportFactory");
            IInfoObject infoObject = (IInfoObject)infoObjects.get(0); 
/*  if (infoObjects != null) {
            Iterator lReportListIterator = lReportList.iterator();
            while (lReportListIterator.hasNext()) {
                IInfoObject infoObject = (IInfoObject) lReportListIterator.next();*/                
            clientDoc = new ReportClientDocument();
            clientDoc = reportAppFactory.openDocument(infoObject,0, java.util.Locale.US);
            System.out.println("Report "+ infoObject.getTitle() +" Opened");   
            switch_tables(clientDoc.getDatabaseController());
         }catch(ReportSDKException re){            
            re.printStackTrace();
         }catch(SDKException re){
            re.printStackTrace();
         }
      }
       }
   }
   private static void switch_tables(DatabaseController databaseController) throws ReportSDKException {
     //Report can be opened from the relative location specified in the CRConfig.xml, or the report location
//tag can be removed to open the reports as Java resources or using an absolute path (absolute path not recommended
//for Web applications).
final String REPORT_NAME = "change_db_location/simplereport.rpt";
final String DBUSERNAME = "vantech";
final String DBPASSWORD = "vantech";
final String CONNECTION_STRING = "!com.microsoft.jdbc.sqlserver.SQLServerDriver!jdbc:microsoft:sqlserver://10.50.212.103:1433;DatabaseName={database};user={userid};password={password}";
final String TRUSTEDCON = "false";
final String PREQESERVERNAME = "jdbc:microsoft:sqlserver://10.50.212.103:1433";
final String SERVERTYPE = "JDBC (JNDI)";
final String DATABASE_DLL = "crdb_jdbc.dll";
final String DATABASE = "Xtreme";
final String DBCLASSNAME = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
final String USEJDBC = "true";
final String DATABASE_NAME = "Xtreme";
final String SERVERNAME = "jdbc:microsoft:sqlserver://10.50.212.103:1433"; 
final String CONNECTIONURL = "jdbc:microsoft:sqlserver://10.50.212.103:1433";
final String SERVER = "10.50.212.103";
        //Open report.
    ReportClientDocument boReportClientDocument = new ReportClientDocument();
    boReportClientDocument.open(REPORT_NAME, 0);
    // Set DB Username and Password
    boReportClientDocument.getDatabaseController().logon(DBUSERNAME, DBPASSWORD);
    // Create the two connectioninfo objects to use
    IConnectionInfo oldConnectionInfo =  new ConnectionInfo();
    IConnectionInfo newConnectionInfo = new ConnectionInfo();
    // Assign the old Connection info to the reports current info
    DatabaseController dbController = boReportClientDocument.getDatabaseController();
    oldConnectionInfo = dbController.getConnectionInfos(null).getConnectionInfo(0);                                        
    // If this connection needed parameters, we would use this field.   
    Fields pFields = null;
    // Create a new propertybag for the new location
    PropertyBag boPropertyBag1 = new PropertyBag();
    // Set new table logon properties
    boPropertyBag1.put("JDBC Connection String", CONNECTION_STRING);
    boPropertyBag1.put("Trusted_Connection", TRUSTEDCON);
    boPropertyBag1.put("PreQEServerName", PREQESERVERNAME);
    boPropertyBag1.put("Server Type", SERVERTYPE);
    boPropertyBag1.put("Database DLL", DATABASE_DLL);
    boPropertyBag1.put("Database", DATABASE);
    boPropertyBag1.put("Database Class Name", DBCLASSNAME);
    boPropertyBag1.put("Use JDBC", USEJDBC);
    boPropertyBag1.put("Database Name", DATABASE_NAME);
    boPropertyBag1.put("Server Name", SERVERNAME);
    boPropertyBag1.put("Connection URL", CONNECTIONURL);
    boPropertyBag1.put("Server", SERVER);
    // Assign the properties to the connection info
    newConnectionInfo.setAttributes(boPropertyBag1);
    // Set the DB Username and Pwd
    newConnectionInfo.setUserName(DBUSERNAME);
    newConnectionInfo.setPassword(DBPASSWORD);
    // The Kind of connectionInfos is SQL
    newConnectionInfo.setKind(ConnectionInfoKind.SQL);
    // set the parameters to replace.
    // The 4 options are:
    // _doNotVerifyDB 
    // _ignoreCurrentTableQualifiers 
    // _mapFieldByRowsetPosition 
    // _useDefault  
    int replaceParams = DBOptions._ignoreCurrentTableQualifiers + DBOptions._doNotVerifyDB;
    // Now replace the connections  
    dbController.replaceConnection(oldConnectionInfo, newConnectionInfo, pFields, replaceParams);
    //Store the report source in session, will be used by the CrystalReportViewer.
    //session.setAttribute("reportSource", boReportClientDocument.getReportSource());
    //Launch CrystalReportViewer page that contains the report viewer.
    //response.sendRedirect("CrystalReportViewer.jsp");
   }
 } 

希望这对你有帮助。

谢谢,Sachin