MultiConnectCloud › API Deployments
8. Connect to a database
Linking a Database deployment lets your API through that database's firewall. That is all it does: it does not add a connection string to your API. You set that yourself, as a secret environment variable.
Link a database
- In the Database deployment, allow linked API deployments in its Network Access section. See the Database Guide.
- Link it in one of two ways:
- When you create the API: Linked Database in the Access & Database step.
- Later: on the API's page, in Linked Database, pick a database and click Link.
- The Linked Database section shows the database Host (host and port).
- Add the connection string as an environment variable with Secret set to Yes, using that host and port and the database's own username and password.
Script 8.1: A connection string as a secret environment variable
DATABASE_URL=<connection string built from the Host shown in Linked Database, and the database's username and password>
| Rule | Detail |
|---|---|
| Same project | The database must be in the same project as the API |
| Active | The database must be active |
| One at a time | An API links to one database |
| Redeploys | Linking or unlinking redeploys your current build |
| Startup | The firewall is updated moments after your API's containers are placed. If your API migrates the database at startup, let it retry the connection for a minute or two |
The host stays the same if the database fails over, so you do not need to change anything when that happens.
To unlink, click Unlink, then remove the connection string from your variables. A database cannot be deleted while an API is linked to it.

