# Determine if a database connection is good

**URL:** <https://forum.inductiveautomation.com/t/determine-if-a-database-connection-is-good/5727>\
**Category:** Ignition\
**Created:** [January 23, 2013, 3:59pm UTC](https://forum.inductiveautomation.com/t/determine-if-a-database-connection-is-good/5727 "2013-01-23T15:59:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![TCK](https://avatars.discourse-cdn.com/v4/letter/t/3e96dc/32.png) [@TCK](https://forum.inductiveautomation.com/u/TCK)\
**Post date:** [January 23, 2013, 3:59pm UTC](https://forum.inductiveautomation.com/t/determine-if-a-database-connection-is-good/5727/1 "2013-01-23T15:59:11Z")

</div>

On my main form when my program opens I have some labels as flags to indicate if there is a good connection to a couple of PLC’s. I did this by creating tags to diagnostics/is connected in the gateway.

Am I able to grab the database status flag in the gateway somehow to indicate a good connection to the database?

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [January 23, 2013, 4:09pm UTC](https://forum.inductiveautomation.com/t/determine-if-a-database-connection-is-good/5727/2 "2013-01-23T16:09:17Z")

</div>

Yes, those tags are located in the System folder under System \> Gateway \> Database \> YourDatabaseName \> Available.

---

<div class="post-metadata">

**Author:** ![TCK](https://avatars.discourse-cdn.com/v4/letter/t/3e96dc/32.png) [@TCK](https://forum.inductiveautomation.com/u/TCK)\
**Post date:** [January 23, 2013, 4:29pm UTC](https://forum.inductiveautomation.com/t/determine-if-a-database-connection-is-good/5727/3 "2013-01-23T16:29:38Z")

</div>

Great! Thanks!

---

<div class="post-metadata">

**Author:** ![w.mandelli](https://avatars.discourse-cdn.com/v4/letter/w/9e8a1a/32.png) [@w.mandelli](https://forum.inductiveautomation.com/u/w.mandelli)\
**Post date:** [September 17, 2013, 9:07pm UTC](https://forum.inductiveautomation.com/t/determine-if-a-database-connection-is-good/5727/4 "2013-09-17T21:07:25Z")

</div>

Those tags works for me if I stop and start the MySQL service.  
Unfortunately they don’t if I drop the schema: in this case i still get a “valid” connection from the gateway and a connection “Available” from the tag.  
In the Database Query Browser i still see the connection available with no table inside.  
Running version 7.6.2

Am I missing anything?

---

<div class="post-metadata">

**Author:** ![george](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/george/32/14066_2.png) [@george](https://forum.inductiveautomation.com/u/george)\
**Post date:** [September 20, 2013, 1:30pm UTC](https://forum.inductiveautomation.com/t/determine-if-a-database-connection-is-good/5727/5 "2013-09-20T13:30:52Z")

</div>

The tag is most likely just validating that the database itself is there and not any particular tables within it.

You could try the following:

In the Gateway web page click Configure, then select Connections (under Databases) then find your connection in the list and click Edit.

Scroll down to the bottom and tick the checkbox “Show advanced properties”.

Within the Connection Testing section there should be a Validation Query entry that will probably  
be just SELECT 1.

You could change this to SELECT column\_name FROM table\_name to check for the presence of a particular table.

Scroll down and Save Changes.

---

<div class="post-metadata">

**Author:** ![greg.simpson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/greg.simpson/32/3135_2.png) [@greg.simpson](https://forum.inductiveautomation.com/u/greg.simpson)\
**Post date:** [October 14, 2013, 9:35pm UTC](https://forum.inductiveautomation.com/t/determine-if-a-database-connection-is-good/5727/6 "2013-10-14T21:35:15Z")

</div>

w.mandelli,

```
 I just tested this in 7.6.4-rc1 and it works fine using the method that Travis suggested. Unfortunately I don't have an installation of 7.6.2 to test with. But I was able to stop the MySQL service and the boolean for available cleared. Can you test this again?
```
