Using more than one database connection in a project

Hi, I am working in a project where I need to consult data from more than one database (Postgres and MySQL). I am not using tags because I need to change the text of the queries dinamically, so I am writing the queries as text in some invisible labels, and making my charts execute those texts as SQL queries.

I have several connections defined in the gateway configuration (and they really work). The problem is that in the “Projects” menu I can choose the default database for the project, but I can choose only one. When I select the MySQL connection, the part that uses the PostgreSQL one stops working, and vice versa.

So, the question is: how can I use more than one defined database connection in my project? Is there some way to say the gateway to use more connections in a project than the default one? Thanks in advance.

You don’t need to use the default datasource for queries - it is designed so that you can easily swing your entire project to another database. There is a dropdown list that allows you to select your datasource on the window where your query is. You can use whatever of any of your datasources (different SQL database connections) in your queries, DB bindings, and scripts.

A different question along the same line (or maybe not…). What if you have multiple database connections and you want to write a query that will gather information from more than one database in one query. What would you set the database connection to? Would you just set it to one database and then do the databasename.tablename.column structure in the query to get to the other database?

I’m curious because I’ll be doing this soon so I should probably figure it out before hand so I don’t look like an idiot later on :stuck_out_tongue:

If the two databases are within the same database server than you can specify:

databasename.tablename.columnname

If they are from different databases you can’t gather data from the same SQL query. You have to combine them through scripting.

1 Like

Thanks for the answers, I forgot the detail about choosing the connection to use in the query menu.

Having 2 projects on the same connection, would that cause any issues? Basically adding another PLC on the same connection through Kepware

No problem. If you start encountering any performance issues, increase the pool size for the DB connection. (This can be needed with large, complex, single projects as well.)

1 Like