🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
SQL Database
This page was created by Alexandra on 2018-11-07. Last edited by Wikiadmin on 2026-07-29.

You can use this page to understand how an MDriven application relates its model to a SQL database and where to find the tasks for configuring, evolving, and integrating that database.

SQL databases in an MDriven application

A database is an organized collection of structured data. In an MDriven application, the database stores the application data, while the model defines the structure that the database must match.

For example, if your application stores customer names and product prices, those values are database data. When you change the corresponding model structure, you must ensure that the database structure is updated to match it.

SQL (Structured Query Language) is the language used to communicate with SQL databases. SQL can query, insert, update, delete, and define database objects. Use SQL when you need to work directly with the database; use OCL when you express model-level logic in MDriven.

Keep the database aligned with the model

Database evolve is the process in which MDriven Designer or MDrivenServer changes the database to match the current model.

Use this workflow when you change the model:

  1. Make the required change in the model.
  2. Run or allow the database evolve process to update the database structure.
  3. Review evolve messages. A message that a change will not be evolved means that the evolve engine cannot handle that change automatically.
  4. Apply the required change manually in the SQL server when automatic evolution is not available.

Do not assume every model change can be applied automatically. Plan and review database changes before applying them to a database that contains important data.

Attribute defaults and nullability

The DefaultDBValue property on an attribute affects how the evolve mechanism creates that attribute in SQL Server. Its behavior is related to the attribute's allow-null setting. See Documentation:DefaultDBValue for the distinction between initial values, database default values, and nullability.

Configure a production database

Production deployment packages can include PostgreSQL, MySQL, or MSSQL database configurations. The provided Docker Compose setup places the chosen database, MDrivenServer, and Turnkey on a shared internal network.

To connect MDrivenServer to the selected database:

  1. Start the deployment for the first time with docker compose up -d. The supplied initialization scripts create the database schema.
  2. Open the MDrivenServer URL and sign in.
  3. Select Running > Model.
  4. If the application is running, select Pause App.
  5. Set Connection Type to the database type you selected: MSSqlServer, MySQL, or PostgreSQL.
  6. Set Alternate Connection String to the connection string for that database, using passwords that match its environment file.
  7. Finalize the configuration and upload the model as described in Documentation:Configuring Production Databases PostgreSQL MySQL MSSQL.

The deployment stores database files on the host so data persists across container restarts and updates:

Database Host data directory
PostgreSQL /postgres-data
MySQL /mysql-data
MSSQL /mssql-data

Work with external SQL changes

MDrivenServer maintains its own change tracking as a dirty list of objects used by clients. It does not automatically detect changes made directly to underlying SQL Server tables by another client or service.

If a legacy system or another service writes to the same SQL Server database, enable tracking only for the tables that external systems can change. Then implement the external-change handling pattern described in Documentation:SQL Server change tracking. That pattern finds changed primary keys and invalidates the corresponding objects so clients reload current data.

Connection and script problems

If SQL Server authentication succeeds but login fails because the certificate chain is not trusted, review Documentation:SQL not trusted. The documented development connection-string pattern includes TrustServerCertificate=True; whether you use integrated security depends on your SQL Server login configuration.

If you cannot save an ECO model to a SQL database, see Documentation:Problem saving database script.

See also