# Can I use a script to reconnect a database?

**URL:** <https://forum.inductiveautomation.com/t/can-i-use-a-script-to-reconnect-a-database/38018>\
**Category:** General Discussion\
**Tags:** ignition79\
**Created:** [August 24, 2020, 12:03pm UTC](https://forum.inductiveautomation.com/t/can-i-use-a-script-to-reconnect-a-database/38018 "2020-08-24T12:03:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![patrick.garceau](https://avatars.discourse-cdn.com/v4/letter/p/76d3ee/32.png) [@patrick.garceau](https://forum.inductiveautomation.com/u/patrick.garceau)\
**Post date:** [August 24, 2020, 12:03pm UTC](https://forum.inductiveautomation.com/t/can-i-use-a-script-to-reconnect-a-database/38018/1 "2020-08-24T12:03:17Z")

</div>

We have a database that is valid, but sometimes it gets to a status that says Reconnecting. The way to fix this is to edit the connection and save, then it will become Valid again. This is nice, but it relies on my mouse clicking something. Is there a way to do this automatically when I get the connection error? I would need to detect that the database is in error or FAULTED as the log says.

Thanks,

---

<div class="post-metadata">

**Author:** ![Sanderd17](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sanderd17/32/8735_2.png) [@Sanderd17](https://forum.inductiveautomation.com/u/Sanderd17)\
**Post date:** [August 24, 2020, 12:21pm UTC](https://forum.inductiveautomation.com/t/can-i-use-a-script-to-reconnect-a-database/38018/2 "2020-08-24T12:21:12Z")

</div>

See [`system.db.getConnectionInfo`](https://docs.inductiveautomation.com/display/DOC80/system.db.getConnectionInfo) and [`system.db.setDatasourceEnabled`](https://docs.inductiveautomation.com/display/DOC80/system.db.setDatasourceEnabled)

Those functions should enable you to detect the DB is down, and the reset the connection.

---

<div class="post-metadata">

**Author:** ![patrick.garceau](https://avatars.discourse-cdn.com/v4/letter/p/76d3ee/32.png) [@patrick.garceau](https://forum.inductiveautomation.com/u/patrick.garceau)\
**Post date:** [August 24, 2020, 1:34pm UTC](https://forum.inductiveautomation.com/t/can-i-use-a-script-to-reconnect-a-database/38018/3 "2020-08-24T13:34:10Z")

</div>

Thanks, this works. Running this script every hour is no issue.

---

<div class="post-metadata">

**Author:** ![patrick.garceau](https://avatars.discourse-cdn.com/v4/letter/p/76d3ee/32.png) [@patrick.garceau](https://forum.inductiveautomation.com/u/patrick.garceau)\
**Post date:** [August 24, 2020, 4:09pm UTC](https://forum.inductiveautomation.com/t/can-i-use-a-script-to-reconnect-a-database/38018/4 "2020-08-24T16:09:09Z")

</div>

I have a problem on Ignition 7.9.6  
com.inductiveautomation.ignition.designer.gui.tool’ object has no attribute ‘setDatasourceEnabled’  
Is this a problem with the version? It is specified on the documentation, so what is it?

---

<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:** [August 24, 2020, 4:37pm UTC](https://forum.inductiveautomation.com/t/can-i-use-a-script-to-reconnect-a-database/38018/5 "2020-08-24T16:37:55Z")

</div>

Why are you still using 7.9.6? That version is years out of date. That said, the function should still exist. What’s the actual script you’re using?

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [August 24, 2020, 6:32pm UTC](https://forum.inductiveautomation.com/t/can-i-use-a-script-to-reconnect-a-database/38018/7 "2020-08-24T18:32:13Z")

</div>

Sometimes you set up a application for a client and it works well for years, so there’s no need or want to update, why fix what isn’t broken. This leads me to dealing with some projects that are 7.4 or less of Ignition. I don’t think most developers have much say in what version we’re using unfortunately.

---

<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:** [August 24, 2020, 7:04pm UTC](https://forum.inductiveautomation.com/t/can-i-use-a-script-to-reconnect-a-database/38018/8 "2020-08-24T19:04:26Z")

</div>

Appreciated, _but_ if you start having a problem that you think might be a bug, the first thing we’re going to tell you is update, because it’s in everyone’s best interest to find out if a bug is already fixed before spending time troubleshooting or investigating further.

---

<div class="post-metadata">

**Author:** ![patrick.garceau](https://avatars.discourse-cdn.com/v4/letter/p/76d3ee/32.png) [@patrick.garceau](https://forum.inductiveautomation.com/u/patrick.garceau)\
**Post date:** [August 25, 2020, 3:39pm UTC](https://forum.inductiveautomation.com/t/can-i-use-a-script-to-reconnect-a-database/38018/9 "2020-08-25T15:39:07Z")

</div>

So I updated my version from 7.9.6 to version 7.9.14 which is the lates that the licence will have. Also installed the Vision module as I had previous experience with some script not able to run without that module installed, a bug in Ignition on how they package their code base.

The function is working now, so i’ll see if the future I have no more bug due to the jdbc driver.

Thanks,
