Cannot make a database query in a nas Pre Processing script

Document ID : KB000123072
Last Modified Date : 17/12/2018
Show Technical Document Details
I am trying to make a database query in a nas pre- processing script. If I run the script in the editor, it runs fine.
It connects to the database, makes the query and prints the desired results.
However, when I try to enrich events with this script this line in the script throws an error:

local returnCode =,false)

(note: connectString is set previously and works when run through the editor)

The output message is: nas: PREPROCESSOR ERROR: scripts/cdm_event:71: attempt to index global 'database' (a nil value)

Why does the script throw an error when run through pre-processing?
nas pre-processing scripts do not allow the use of database related methods due to the impact on the slow down of alarms that these could cause.
These methods can be used with AO rules which can execute the script which invokes the database methods.