OutSystems Platform allows your applications to access data of an external database.
To work with data of an external database in your application, you need to follow these steps:
For a list of supported database engines using this procedure, see the System Requirements.
In our Sales app we would like to list Order records with the Customer and Product information, and allow users to modify them. The data is stored in the 'customer', 'order' and 'product' tables of an external database called 'salesdb'.
In the environment management console, under Administration - Database Connection, set up a new database connection to your external database. Call it 'SalesDB Connection'.
The user defined in this database connection determines the privileges of access to the data, namely the ability to read, create, update or delete data.
In the application add a new extension module, name it 'SalesDB_Connector', and define the entities based on the database tables:
As result, the 'customer', 'order' and 'product' entities are defined in the extension.
Click the '1-Click Publish' button to publish it.
After publishing the extension, can configure the database connection that will be used by the logical database you defined earlier. This setting enables you to change easily which database connection the extension uses.
Click 'Configure', and in the environment management console, select the 'SalesDB Connection' to be used by the extension.
In your app, add a dependency on the extension module. Learn how to add dependencies.
Now we can create the screens that list and modify order records.
In some cases you need to select the database based on run-time data. Typically the applicable databases share the same schema, but they have different data.
In these scenarios you can use the 'DatabaseConnection_SetConnectionStringForSession' action of the PlatformRuntime API.
Use Foreign Entities