# Database Properties via Python

**URL:** <https://forum.inductiveautomation.com/t/database-properties-via-python/28827>\
**Category:** Ignition\
**Tags:** python\
**Created:** [October 4, 2019, 1:38pm UTC](https://forum.inductiveautomation.com/t/database-properties-via-python/28827 "2019-10-04T13:38:15Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![lrhyrne](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrhyrne/32/12097_2.png) [@lrhyrne](https://forum.inductiveautomation.com/u/lrhyrne)\
**Post date:** [October 4, 2019, 1:38pm UTC](https://forum.inductiveautomation.com/t/database-properties-via-python/28827/1 "2019-10-04T13:38:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![wking](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/wking/32/21823_2.png) [@wking](https://forum.inductiveautomation.com/u/wking)\
**Post date:** [October 4, 2019, 2:40pm UTC](https://forum.inductiveautomation.com/t/database-properties-via-python/28827/2 "2019-10-04T14:40:25Z")

</div>

[https://docs.inductiveautomation.com/display/DOC80/system.db.getConnectionInfo](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.

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

```

returns:

```auto
>>> 
MES
None
MYSQL
Valid

Valid
1.49840794156
0
8
SELECT 1
>>> 

```

---

<div class="post-metadata">

**Author:** ![lrhyrne](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrhyrne/32/12097_2.png) [@lrhyrne](https://forum.inductiveautomation.com/u/lrhyrne)\
**Post date:** [October 4, 2019, 3:05pm UTC](https://forum.inductiveautomation.com/t/database-properties-via-python/28827/3 "2019-10-04T15:05:21Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![wking](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/wking/32/21823_2.png) [@wking](https://forum.inductiveautomation.com/u/wking)\
**Post date:** [October 4, 2019, 3:29pm UTC](https://forum.inductiveautomation.com/t/database-properties-via-python/28827/4 "2019-10-04T15:29:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lrhyrne](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrhyrne/32/12097_2.png) [@lrhyrne](https://forum.inductiveautomation.com/u/lrhyrne)\
**Post date:** [October 4, 2019, 4:18pm UTC](https://forum.inductiveautomation.com/t/database-properties-via-python/28827/5 "2019-10-04T16:18:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lrhyrne](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrhyrne/32/12097_2.png) [@lrhyrne](https://forum.inductiveautomation.com/u/lrhyrne)\
**Post date:** [October 4, 2019, 4:46pm UTC](https://forum.inductiveautomation.com/t/database-properties-via-python/28827/6 "2019-10-04T16:46:35Z")

</div>

yes, JDBC connection string.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 4, 2019, 4:57pm UTC](https://forum.inductiveautomation.com/t/database-properties-via-python/28827/7 "2019-10-04T16:57:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lrhyrne](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrhyrne/32/12097_2.png) [@lrhyrne](https://forum.inductiveautomation.com/u/lrhyrne)\
**Post date:** [October 4, 2019, 5:10pm UTC](https://forum.inductiveautomation.com/t/database-properties-via-python/28827/8 "2019-10-04T17:10:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lrhyrne](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrhyrne/32/12097_2.png) [@lrhyrne](https://forum.inductiveautomation.com/u/lrhyrne)\
**Post date:** [October 16, 2019, 8:13pm UTC](https://forum.inductiveautomation.com/t/database-properties-via-python/28827/9 "2019-10-16T20:13:24Z")

</div>

Simple, I just used the followning pythong snippet:

system.net.getHostName()
