# Script working in console but not event

**URL:** <https://forum.inductiveautomation.com/t/script-working-in-console-but-not-event/82919>\
**Category:** Ignition\
**Tags:** scripting, vision\
**Created:** [December 8, 2023, 9:36pm UTC](https://forum.inductiveautomation.com/t/script-working-in-console-but-not-event/82919 "2023-12-08T21:36:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Why\_Me](https://avatars.discourse-cdn.com/v4/letter/w/b4bc9f/32.png) [@Why\_Me](https://forum.inductiveautomation.com/u/Why_Me)\
**Post date:** [December 8, 2023, 9:36pm UTC](https://forum.inductiveautomation.com/t/script-working-in-console-but-not-event/82919/1 "2023-12-08T21:36:07Z")

</div>

Ive got a script running as an event script on a time stamp the queries a DB 60 seconds ago and takes away the current value from the historical value. It works absolutely fine in script console but doesnt seem to do anything in the event script.. any ideas?

```auto
time=system.date.addMinutes(system.date.now(),-1)
sqltime=system.date.format(time,"YYYY-MM-dd HH:mm:ss")
sql="SELECT top(1) * FROM Pressure_History where Current_DateTime > '%s' "%sqltime
res=system.db.runQuery(sql)
pressure=res[0]['Pressure']
pressure = int(pressure)
currpress = system.tag.readBlocking("[default]Test/Pressure")[0].value
final = pressure - currpress
system.tag.writeAsync("[default]Test/Pressure diff 1 min",final)
print final

```

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [December 8, 2023, 9:42pm UTC](https://forum.inductiveautomation.com/t/script-working-in-console-but-not-event/82919/2 "2023-12-08T21:42:10Z")

</div>

Designer script console behaves like a modified vision scope. Most likely your event is firing in the gateway scope, meaning that you need to look at the required parameters for any system function calls.

The error is most likely in regards to your call to `system.db.runQuery()`, which requires you to define a target database connection when called in a gateway scope. [Manual Page](https://docs.inductiveautomation.com/display/DOC81/system.db.runQuery)

---

<div class="post-metadata">

**Author:** ![Why\_Me](https://avatars.discourse-cdn.com/v4/letter/w/b4bc9f/32.png) [@Why\_Me](https://forum.inductiveautomation.com/u/Why_Me)\
**Post date:** [December 8, 2023, 9:43pm UTC](https://forum.inductiveautomation.com/t/script-working-in-console-but-not-event/82919/3 "2023-12-08T21:43:57Z")

</div>

solved in 1mate thanks, added "MicrosoftSQL" to query
