# Problem with SQL Query in a Tag change script

**URL:** <https://forum.inductiveautomation.com/t/problem-with-sql-query-in-a-tag-change-script/15244>\
**Category:** Ignition\
**Created:** [September 4, 2017, 5:59pm UTC](https://forum.inductiveautomation.com/t/problem-with-sql-query-in-a-tag-change-script/15244 "2017-09-04T17:59:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Enginiosys](https://avatars.discourse-cdn.com/v4/letter/e/7ea924/32.png) [@Enginiosys](https://forum.inductiveautomation.com/u/Enginiosys)\
**Post date:** [September 4, 2017, 5:59pm UTC](https://forum.inductiveautomation.com/t/problem-with-sql-query-in-a-tag-change-script/15244/1 "2017-09-04T17:59:09Z")

</div>

Good evening all,

We are actually facing some difficulties to put an SQL query inside a Tag change Script.

We are actually having an error message looking like :

> .......", line 7, in valueChanged at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:364) at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runPrepQuery(AbstractDBUtilities.java:290) at sun.reflect.GeneratedMethodAccessor66.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) java.lang.Exception: java.lang.Exception: Error executing system.db.runPrepQuery(select \* from HISTORY, , [null], .\>

When we put the query in a simple button for example or in the Scrpting console, it works perfectly, but on the tag change script, it never works. Did we missed something ?

King regards,  
Yassine

---

<div class="post-metadata">

**Author:** ![Enginiosys](https://avatars.discourse-cdn.com/v4/letter/e/7ea924/32.png) [@Enginiosys](https://forum.inductiveautomation.com/u/Enginiosys)\
**Post date:** [September 4, 2017, 7:08pm UTC](https://forum.inductiveautomation.com/t/problem-with-sql-query-in-a-tag-change-script/15244/2 "2017-09-04T19:08:53Z")

</div>

here is a picture f the very basic script

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/8/825ad735c47bbfbbaafa2db4b6d1a75c077da2be.jpg)

---

<div class="post-metadata">

**Author:** ![accyroy](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/accyroy/32/3386_2.png) [@accyroy](https://forum.inductiveautomation.com/u/accyroy)\
**Post date:** [September 4, 2017, 7:40pm UTC](https://forum.inductiveautomation.com/t/problem-with-sql-query-in-a-tag-change-script/15244/3 "2017-09-04T19:40:45Z")

</div>

The tag events are run in the gateway scope, so they do not have a default database, you probably need to include your db connection name in the runPrepQuery call.

---

<div class="post-metadata">

**Author:** ![jlawson84](https://avatars.discourse-cdn.com/v4/letter/j/d2c977/32.png) [@jlawson84](https://forum.inductiveautomation.com/u/jlawson84)\
**Post date:** [September 7, 2017, 10:49pm UTC](https://forum.inductiveautomation.com/t/problem-with-sql-query-in-a-tag-change-script/15244/5 "2017-09-07T22:49:41Z")

</div>

accyroy is correct. You will need to list your DB you are pulling from.

example: system.db.runPrepUpdate(‘DELETE FROM PROD\_Line\_Summary WHERE RunUUID = ?’,[RunID],“ **Analysis** ”)

The DB is in bold in the example above. Hope this helps.

---

<div class="post-metadata">

**Author:** ![Enginiosys](https://avatars.discourse-cdn.com/v4/letter/e/7ea924/32.png) [@Enginiosys](https://forum.inductiveautomation.com/u/Enginiosys)\
**Post date:** [September 8, 2017, 7:38am UTC](https://forum.inductiveautomation.com/t/problem-with-sql-query-in-a-tag-change-script/15244/6 "2017-09-08T07:38:42Z")

</div>

Thank you guys!  
It works perfectly !
