Guides and Articles

Use this documentation when building your Tekla EPM apps

Code example: Connect Tekla EPM database remotely

Updated: 23 May 2019

With Remote Server the debug logging is easier than with direct connection

There are two ways to connect Tekla EPM: direct and remote. In this guide you will see how to connect remotely with the Tekla EPM database using the Tekla EPM Open API.

It's usually preferred to use the remote connection instead of the direct one: the remote interface supports logging. 

Tekla EPM Remote Service required

When using the Remote Server service you must have Tekla EPM Remote Service (usually used for Tekla EPM GO) installed. Create an External User, and give that user permissions to log in and view jobs. Start out giving the external user full permissions to everything. When it's working, you can remove privileges that are unnecessary. Update the code to use the proper IP address of the remote server, port used by the remote server, username and password, then add any command available. 

Creating the remote connection with Tekla EPM

Follow these steps to create the remote connection.

 

  1. Create new FabSuiteAPI object that uses the IFabSuiteAPI interface. You will execute the requests against the FabSuiteAPI object and get responses back in xml string. 
    public partial class TeklaEPMOpenAPIExampleF : Form
    {
        FabSuite.FabSuiteAPI.IFabSuiteAPI fsAPI = new FabSuite.FabSuiteAPI.FabSuiteAPI();

       

    • Set following connection strings:
      • connection_ipAddress: ip address of the computer that is running the Tekla EPM Remote Server service
      • connection_port: port that the Tekla EPM Remote Server service is listening on, the default is 9154
      • connection_username: the Tekla EPM user name of a user that has been given remote login privileges
      • connection_password: the Tekla EPM password
          string connection_ipAddress = "localhost";  
          string connection_port = "3306"; 
          string connection_username = "admin"; 
          string connection_password = "EPM";
      
          private string connectionGUID = "";

      connectionGUID is returned by a successful ConnectRemote command. Save the ConnectionGUID for use with subsequent commands.

    • When user clicks the Connect button, create new request object fsreqFabSuiteXMLRequest: 
      private void ConnectButton_Click(object sender, EventArgs e)
      {
          //declare the request object
          reqFabSuiteAPI.fsreqFabSuiteXMLRequest request = new reqFabSuiteAPI.fsreqFabSuiteXMLRequest();

       

    • Create new connectRemote object to be requested. Use the user name and password defined earlier: 
          reqFabSuiteAPI.fsreqConnectRemote connectRemoteCommand = new reqFabSuiteAPI.fsreqConnectRemote();
          connectRemoteCommand.Username = username;
          connectRemoteCommand.Password = password;

       

    • Request object takes a list as a property, so set the connectRemote as the first item in the list: 
          request.ConnectRemote = new reqFabSuiteAPI.fsreqConnectRemote[1];
          request.ConnectRemote[0] = connectRemoteCommand;

       

    • Establish a remote connection to the Tekla EPM database by executing the request. Execution will respond with fsresFabSuiteXMLResponse object:
          resFabSuiteAPI.fsresFabSuiteXMLResponse response = executeCommand(request);

       

    • Check that the remote connection was created and there were no errors:
          //first check for an XMLError element
          if (response.XMLError != null && response.XMLError.Length > 0)
              MessageBox.Show(response.XMLError[0]);  //fatal error
          else
          {
              //The get the ConnectRemote response object and check if it was successful
              resFabSuiteAPI.fsresConnectRemote connectRemoteResponse = response.ConnectRemote[0];
              if (!connectRemoteResponse.Successful)
                  MessageBox.Show(connectRemoteResponse.ErrorMessage);  //command failed
              else
              {
                  // command successful, save the ConnectionGUID for use with subsequent commands.
                  connectionGUID = connectRemoteResponse.ConnectionGUID;
                  MessageBox.Show("connected!");
              }
          }