Database Properties via Python

Wondering if there was a way to retrieve the MySQL database connection string or connection string information (hosting machine name, dbname specifically) via python?

https://docs.inductiveautomation.com/display/DOC80/system.db.getConnectionInfo

that function returns dataset with name of db and dbtype (mysql ,mssql). But, only in the gateway scope? I don’t know how you would expose host name.

connectionInfo = system.db.getConnectionInfo('MES')
data = system.dataset.toPyDataSet(connectionInfo)
for col in data:
		for value in col:
			print value

returns:

>>> 
MES
None
MYSQL
Valid

Valid
1.49840794156
0
8
SELECT 1
>>> 

I’m thinking about using a tag I create to store the whole connection string for use anywhere in the client. That is plan B…

Sounds dangerous…
How come you need to know the connection string, out of curiosity? You’re talking about the JDBC connection string?

Ok. I’m using MySQL and a script I am using fires off another script that queries the database from outside Ignition entirely, so I need a method to connect to the db regardless of what machine fired the script.

yes, JDBC connection string.

Do you really need dynamic access? I mean, would it be that much extra maintenance burden to have a fixed map of database connection names -> DB hostnames/connection strings? You could put it in a dataset tag or something.

Yes, dynamic, ad-hoc access is manditory. This is a workaround for a broken easy chart save button. I’m firing off the external script to mine the database for me. Problem is there is no telling where the script will be fired from due to clients running from a number of consoles on another machine than the gateway/database server.

Simple, I just used the followning pythong snippet:

system.net.getHostName()

1 Like