Connections to External Databases for Object Types

You can set M-Files to update object types to and from an external database. Objects that use an external database connection can also contain properties that are not synchronized with the external database.

This section tells you how to set object types to use an application connection to an external database. To use the legacy database connection, see the section "Using the Legacy Database Connection for Object Types".

Prerequisites

Take note of this important information before you start the setup:

  • Before you set up an application connection to an external database, you must have an external object type connector installed and enabled.
  • If you use replication and application connection to an external database service, you must configure the connection separately for each vault in the replication scheme. Make sure that the necessary configuration changes are also made to each vault. We also recommend that you read the section Replication of External Objects of the document Replication and Archiving - User's Guide.
  • It is not possible to include the configuration for External Object Type Connector to replication packages.
  • In SELECT FROM statements, the columns are selected in order of appearance. There is no relation between column and property names, which is why the order must be the same in the SELECT FROM and INSERT INTO statements, and SELECT FROM and UPDATE statements. Also, columns not used in the INSERT INTO and UPDATE statements must always be listed last in the SELECT FROM statement.

To use a connection to external database and to open the service configuration:

  1. Open M-Files Admin and go to a vault.
    1. Open M-Files Admin.
    2. In the left-side tree view, expand an M-Files server connection.
    3. Expand Document Vaults.
    4. Expand a vault.
  2. Expand Metadata Structure (Flat View).
  3. Click Object Types.
    Result:The object type listing is opened in the right pane.
  4. In the right-pane listing, double-click the object type.
    Result:The Object Type Properties dialog is opened.
  5. Go to the Connection to External Database tab and enable the option Use a connection to an external database to import and modify objects that reside in the external database.
  6. Select Application connection.
  7. In Service, select the service.
    OptionDescription
    M-Files OLE DB at vault <name of the vault> Select this option to use the local service.
    M-Files OLE DB from Ground Link proxy <name of the Ground Link proxy> Select this option to establish the connection with a remote service through Ground Link.

    The services that have the (OK) suffix, have a configuration for the object type.

    Result:Information of the service configuration with possible errors is shown.
  8. Click Configure.
    Result:The External Object Type Connector dialog is opened.
To specify the connection settings and to get the source columns:
  1. Expand Service-Specific Settings > Connection to External Database.
  2. In Provider, select the provider for the external database connection.
    Example:Microsoft OLE DB Driver for SQL Server.
    Note: The list of providers shows all the available providers on the server machine that runs the external object type connector. Thus, it can include providers that cannot be used in external database connections.
    The syntax of the connection string is different for each Object Linking and Embedding Database (OLE DB) supplier used for establishing the connection to the external database. If Open Database Connectivity (ODBC) is necessary to create the connection, the data store must be accessed over OLE DB and ODBC. For a list of recommended providers, see Provider Recommendations for External Database Connections.
  3. Optional: If you selected Custom provider (manual configuration), in Custom provider, specify the provider.
  4. Under Connection to External Database, complete one of these steps:
    OptionDescription
    Specify the other settings.

    The correct values are different for each provider and external database.

    For more information, select a setting and see the Info tab.

    In Advanced Options, enter the connection string. Use this option if it is not possible to use the other settings with the selected provider. When you enter the connection string, make sure that all values are correctly enclosed and the connection string has the necessary formatting.
  5. Optional: Under Optional SELECT Statements, define the settings.
    Note: The application connection does not support the Connections to External Databases settings in the Advanced Vault Settings section in M-Files Admin. To use these settings, define them here.
  6. Under Service-Specific Settings, in SELECT Statement, write the SELECT statement for getting source columns from the external database.
    Examples of SELECT statements:

    SELECT CustomerNumber, CustomerName FROM Customer

    SELECT ID, Name + ' ' + Department FROM Company

    SELECT ID, Name, CustomerID FROM Contacts

    SELECT * FROM Customer

    Tip: You can write a multi-line statement.
  7. Click Save.
  8. Optional: To configure a remote service:
    1. Click Apply.
      Result:The Enter Password dialog is opened.
    2. Enter the password that is defined in the Ground Link proxy configuration.
    3. Click OK.
  9. To authenticate the common user, open the Dashboard tab and click Authenticate.
    Result:The Log In dialog is opened.
  10. Enter the common user credentials and click Log In.
    Note: The ODBC driver does not support all special characters. If your connection uses ODBC, the values that contain special characters must be enclosed in curly brackets. The correct format is {username or password}.
  11. In the dialog that is opened, click OK.
  12. Click Save to get the source columns.
    1. Optional: To configure a remote service, repeat step 16.
    Note: You cannot save the configuration if there are no changes.
    Result:The dialog closes and the configuration refreshes. On the Configuration tab, the Column Mappings section shows the source columns that your SELECT statement returned from the external database.
To map the source columns with M-Files properties:
  1. On the Configuration tab, go to Column Mappings and expand a source column node.
  2. In Mapping Type, specify how the source column is mapped to M-Files. Complete one of these steps:
    • To map a source column as the external ID, select Object ID.
      or
    • To map the source column to an M-Files property, select Property. In Target Property, select the M-Files property.
    Note: When you want to map multiple values to a property of the Choose from list (multi-select) data type, the values must be recorded on their own rows in the external database. For example, if you want to map multiple values to the Industry property, the values must be recorded like this:
    ID Customer name City Industry Active
    ABC-123 ESTT Corporation New York 100 1
    ABC-123 ESTT Corporation New York 101 1
    ABC-123 ESTT Corporation New York 108 1

    In this case, however, data can only be read from, not recorded to the external database.

  3. Optional: If the Mapping Type is Property, specify the settings Use in Update Operation and Use in Insert Operation and define the related statements.
    If you want to...Complete the following steps:
    Allow read-only access Set the Use in Update Operation and Use in Insert Operation settings to No. Do not specify the statements in this table.
    Allow users to update but not create or delete information
    1. Set the Use in Update Operation to Yes.
    2. Under Service-Specific Settings, in UPDATE statement, write the UPDATE statement.
    Allow users to update, create, and delete information
    1. Set the Use in Update Operation and Use in Insert Operation settings to Yes.
    2. Under Service-Specific Settings, write the four statements in this table.
    Statement Definition Examples
    UPDATE When a user edits an object in M-Files, M-Files Server edits the corresponding record in the external database using an UPDATE statement. Use a question mark (?) to signal columns to be updated.
    Note: Make sure that the columns are in the same order as they are in the SELECT statement.

    UPDATE Customers SET CustomerName = ? WHERE CustomerID = ?

    UPDATE Contact SET Name = ?, CustomerID = ? WHERE ContactID = ?

    INSERT INTO When a user creates a new object in M-Files, M-Files Server adds a corresponding record into the external database using an INSERT INTO statement. Use a question mark (?) to indicate the value of each column.
    Note: Make sure that the columns are in the same order as they are in the SELECT statement.
    Note: The INSERT INTO statement input to M-Files does not define a value for the ID column. The external database should be set up to automatically provide an ID for new records. For example in SQL Server databases, set the type of the ID column as identity. If the external database cannot produce new ID values, the INSERT INTO statement cannot be used.

    INSERT INTO Customers( CustomerName ) VALUES( ? )

    INSERT INTO ContactPersons( Name, CustomerID ) VALUES( ?, ? )

    Get ID SELECT After a new record has been created with the INSERT INTO statement, M-Files Server gets the ID of the created record with this SELECT statement.

    SELECT MAX( CustomerID ) FROM Customer

    SELECT ID FROM Customers WHERE CustomerName = ?

    DELETE When a user deletes an object from M-Files, M-Files Server deletes the corresponding record in the external database using a DELETE statement. Use a question mark (?) for the ID of the record to be deleted.

    DELETE FROM Customers WHERE CustomerID = ?

    DELETE FROM Contacts WHERE ContactID = ?

  4. Repeat the steps from 21 to 23 for all the necessary source columns.
To take the configuration into use:
  1. Under General Settings, set Enabled to Yes.
    Tip: You can enable and disable the external database connection also with the Disabled check box on the Connection to External Database tab of the Object Type Properties dialog.

    If the connection is disabled, information between the vault and the external database is not synchronized.

  2. Optional: To configure a remote service:
    1. Click Apply.
      Result:The Enter Password dialog is opened.
    2. Enter the password that is defined in the Ground Link proxy configuration.
    3. Click OK.
  3. Click OK to close the Object Type Properties dialog.
The object type is now updated to and from the external database.