0

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

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

我已通读 SDK 并找到了 ReportLogon 类……这是我访问数据库配置属性所需的吗?

谢谢。

4

1 回答 1

0

我正在处理相同的要求。我正在开发一个工具,使用 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");

   }

 } 

希望这会帮助你。

谢谢,萨钦

于 2014-03-29T18:13:40.267 回答