Script working in console but not event

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?

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

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

2 Likes

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