Guides and Articles

Use this documentation when building your Tekla EPM apps

Code example: Connect Tekla EPM database directly

Updated: 23 May 2019

Use direct method if you do not have Tekla EPM Remote Service

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

The direct connection is useful if you do not have Tekla EPM GO, and therefore do not use the Tekla EPM Remote Service.

For this method, create a Tekla EPM user or use the admin user and password. Use the IP address and port of the Tekla EPM Database in your connect command. After you have a connection, use any available command you wish.

The code shown in this example is the same as in Code example: Production control jobs.

Creating direct connection to Tekla EPM

Follow these steps in order to create direct connection to Tekla EPM.

 

  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: the IP address of the Tekla EPM database
      • connection_port: the default port is 3306
      • connection_username: the Tekla EPM user name 
      • connection_password: a Tekla EPM password
          string connection_ipAddress = "localhost";  
          string connection_port = "3306"; 
          string connection_username = "admin"; 
          string connection_password = "EPM";

       

    • 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 connectCommand object to be requested. Use the connection strings defined earlier: 
          reqFabSuiteAPI.fsreqConnect connectCommand = new reqFabSuiteAPI.fsreqConnect();
          connectCommand.IPAddress = connection_ipAddress;
          connectCommand.PortNumber = connection_port;
          connectCommand.Username = connection_username;
          connectCommand.Password = connection_password;

       

    • Request object takes a list as a property, so set the connectCommand as the first item in the list: 
          request.Connect = new reqFabSuiteAPI.fsreqConnect[1];
          request.Connect[0] = connectCommand;

       

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

       

    • Check that the 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 Connect response object and check if it was successful
              resFabSuiteAPI.fsresConnect connectResponse = response.Connect[0];
              if (!connectResponse.Successful)
                  MessageBox.Show(connectResponse.ErrorMessage);  //command failed
              else
                  MessageBox.Show("connected!");
          }
      }