Skip to Content
SBOP SDK

Create and Publish Connection using the Semantic SDK

Tags:

This is a sample created using the Semantic SDK for SAP BusinessObjects Business Intelligence platform 4.1  It demonstrates how to create a new connection from scratch and then publish it to Enterprise.  The sample will create a file SDKTestRelationalConn.cnx in the folder C:\temp and then publish it to Enterprise.

Notes:

  • It is not possible to modify a published connection directly.  It must first be saved locally, at which point you can edit it, and then re-publish it.
  • If you get the error "Could not find driver for MS SQL Server 2008\OLE DB Providers" or similar, it is because you are missing the java parameter:
    -Dbusinessobjects.connectivity.directory="C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\dataAccess\connectionServer"
  • The necessary jar files are all referenced from the jar file sl_sdk.jar which is located in the folder C:\Program Files (X86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\SL SDK\java.  The sl_sdk.jar file does not actually contain the SDK - it merely contains relative paths to all the necessary jar files.

Create and Publish Connection

import com.sap.ip.bi.util.BiConsole.out;
import com.sap.sl.sdk.authoring.cms.CmsResourceService;
import com.sap.sl.sdk.authoring.cms.internal.right.SessionRight;
import com.sap.sl.sdk.authoring.connection.Connection;
import com.sap.sl.sdk.authoring.connection.DatabaseConnection;
import com.sap.sl.sdk.authoring.connection.DatabaseConnection.AuthenticationMode;
import com.sap.sl.sdk.authoring.connection.ConnectionFactory;
import com.sap.sl.sdk.authoring.connection.ConnectionParameter;
import com.sap.sl.sdk.authoring.connection.ConnectionService;
import com.sap.sl.sdk.authoring.connection.RelationalConnection;
import com.sap.sl.sdk.authoring.local.LocalResourceService;
import com.sap.sl.sdk.framework.SlContext;
import com.sap.sl.sdk.framework.cms.CmsSessionService;
import com.businessobjects.framework.*;
import com.crystaldecisions.sdk.exception.SDKException;
import com.crystaldecisions.sdk.framework.CrystalEnterprise;
import com.crystaldecisions.sdk.framework.IEnterprisePrincipal;
import com.crystaldecisions.sdk.framework.IEnterpriseSession;
import com.crystaldecisions.sdk.framework.EnterpriseVersion;
import com.crystaldecisions.sdk.framework.ISessionMgr;
import com.crystaldecisions.sdk.framework.internal.SessionMgr;
import com.crystaldecisions.sdk.properties.IProperties;
import com.businessobjects.dsl.framework.session.SessionManager;

public class CreateConnection {

public static void main(String[] args) {
  IEnterpriseSession sess = null;
 
  try {
   sess = CrystalEnterprise.getSessionMgr().logon("Administrator","Password1", "localhost", "secEnterprise");
  
  out.println("logged on as: " );
  } catch (SDKException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

  SlContext context;
  context = SlContext.create();
  context.getService(CmsSessionService.class).setSession(sess);
 
  CmsResourceService service = context.getService(CmsResourceService.class);

  String tempFolder = "c:\\temp\\";
 
  String userName = "guest"; // dbconnection.getParameter(DatabaseConnection.USER_NAME).getValue();
  String password = "MyPassword" ;
  String dbmsName = "MS SQL Server 2008" ; //dbconnection.getParameter(DatabaseConnection.DBMS).getValue();
  String ntwkName = "OLE DB Providers" ; //dbconnection.getParameter(DatabaseConnection.NETWORK_LAYER).getValue();
  String connName = "vanpgdbsql03.pgdev.sap.corp" ; //dbconnection.getParameter(DatabaseConnection.DATASOURCE).getValue();
  String dbName   = "Xtreme";
  String connectionName = "SDKTestRelationalConn";
   
  com.sap.sl.sdk.authoring.connection.ConnectionFactory connectionFactory;
 
  connectionFactory = context.getService(com.sap.sl.sdk.authoring.connection.ConnectionFactory.class);
 
  RelationalConnection connection = connectionFactory.createRelationalConnection(connectionName, dbmsName, ntwkName);
  connection.getParameter("DATASOURCE").setValue(connName);
  connection.getParameter("DATABASE").setValue(dbName);
  connection.getParameter("USER_NAME").setValue(userName);
  connection.getParameter("PASSWORD").setValue(password);
 
  com.sap.sl.sdk.authoring.local.LocalResourceService localResourceService = context.getService(com.sap.sl.sdk.authoring.local.LocalResourceService.class);
  localResourceService.save(connection, tempFolder + connectionName + ".cnx", true);
 
  service.publish(tempFolder  + connectionName + ".cnx", "/Connections" , true);
}

}

Extra Note: Sample was created by Dan Paulsen