I am integrating FlexSim with PostgreSQL to export simulation data, but I've encountered an issue. When running multiple simulation models simultaneously, PostgreSQL only receives data from the model that finishes last, as expected.
For now, I’ve come up with the solution of creating a separate database for each simulation model. In the 'DataBase Connector' module, I first identify that the database being connected to is the default PostgreSQL, then execute a query to create a new database, like this:
Database.Connection connection = Database.Connection("DatabaseConnector"); connection.connect(); string dbName = "DB1"; string createDBQuery = "CREATE DATABASE \"" + dbName + "\";"; connection.query(createDBQuery); connection.disconnect();
This works, but the problem is that I want to automatically export the simulation data to this newly created database. Currently, I have to manually change the referenced database in the 'DataBase Connector'.
What would probably solve my issue is a command or query that allows me to specify which database I’m connecting to, or even a way to reference this new database name directly within the 'DataBase Name' field in the 'DataBase Connector'.