By configuring a database connection, you can create database queries and add them as steps in your mabl tests. This article explains how to:
- Connect to a database
- Choose a database account
- Add an environment override
- Delete a database connection
Supported database types
mabl supports connections to the following database types:
- MySQL
- Microsoft SQL Server
- PostgreSQL
- MariaDB
- MongoDB
- Oracle
If your team has a use case that requires connecting to a different database type, let us know in the mabl Product Portal.
Connect to a database
Before adding a connection, gather the properties required to connect to your database. Typically, this information takes the form of a connection string, also known as a URI or URL, that contains the connection properties, including the IP address of the host or server, the port number, database name, username, and password.
Only editors and owners can create and edit database connections.
To add a new database connection, go to Configuration > Database connections in the mabl app. Click on + Create database connection to get started.
Sample database connection
Give your database connection a name, and select the database type. In the Connection properties section, enter the information from your database’s connection string in the corresponding field:
-
Hostname/IP: for Microsoft SQL server, this may include an instance name, such as
hostnameSQLEXPRESS - Port: mabl automatically populates the default port number for the selected database type, but you can update this value as needed.
- Database name: this may be referred to as the “Service Name” or “SID” in Oracle, or the “authentication database” in MongoDB
- Credential: the username and password of the database account your tests will use. For extra security, we recommend saving them as cloud credentials. See Choose a database account for what kind of account to create.
- mabl Link Agent override: optional setting to configure a connection to an internal database
Private databases
All database queries execute in the mabl cloud, regardless of whether they occur in the Trainer or during local or cloud execution. If your database is not accessible from the public internet, use one of our recommended options for configuring private database access.
Advanced connection properties
MongoDB databases
For MongoDB databases, you may configure the following optional connection properties:
- Authentication source - specify an alternate authentication database to use when opening the connection.
- Authentication mechanism - specify the authentication mechanism method to use for connection to the server.
- Use mongodb+srv connection protocol - use mongodb+srv:// instead of the default mongodb:// connection protocol
- Use direct connection - force dispatch all operations to the host specified in the connection URI
For details, see the MongoDB connection options documentation.
Microsoft SQL Server databases
If your database queries require mabl Link to connect to a Microsoft SQL Server hosted in Azure, set the Azure SQL Server connection policy to Proxy. Under the Redirect policy, the connection is redirected to a different address after the initial handshake, which times out when the traffic is going through the tunnel. Depending on how your Azure database is set up, Redirect may apply by default, so set Proxy explicitly.
Choose a database account
Database queries run with whatever permissions the account in the connection has, so the account you create for mabl decides what your tests can reach. We recommend the following:
- Create a dedicated account for mabl rather than reusing a person's login or an application service account. A dedicated account is easy to identify in your database's audit logs and easy to rotate or revoke.
- Grant read-only access, scoped to the schemas or tables your queries touch. Most database query steps validate data rather than change it.
- Use a native database login, that is, a username and password the database itself manages. Windows or Active Directory domain logins aren't supported.
mabl encrypts the connection when your database supports it, and accepts self-signed or internal certificates.
Add an environment override
If your team manages similar or identically structured databases in different environments, you can configure connection properties for specific environments by adding environment overrides.
- When a test containing a database query step is run in an environment that you have added as an override, the step will use the connection properties defined in the associated environment override.
- When that same step is run in an environment that is not configured as an environment override, it will use the default connection properties.
For example, you could configure your default connection properties to your dev database and add environment overrides for staging and production. If the test runs in your staging or production environment, it uses the connection properties defined in the associated environment overrides. If the test runs in any other environment besides staging or production, it defaults to your dev database.
To add an environment override, select the environment that should use different connection properties and click on + Add environment override.
Configuring an environment override
Enter the connection properties required for the database. If it is a private database, make sure to use mabl Link or allowlist IPs to ensure mabl can access the database.
Click on Test connection to check the connection.
Delete a database connection
Click on the trash icon to remove a database connection.
Use caution when deleting a database connection:
- Queries associated with a deleted database connection will not work.
- If you associate the orphaned queries with a new database connection, make sure the query is still valid for the new database connection.