Hopefully you are also using the latest version of the NSA, just in case the behavior of the database.query() function changed.
Anyone out there getting a return code and error message from the NSA? I suspect that only happens in the NAS.
I have used the pcall() function to safely call a function that was generating an error. I think the error was causing the NSA to terminate rather than just log an error, but I am not sure. It might help in your situation or maybe not. To use it, you would change this:
local result = database.query(query_string)
...to this:
local status,result = pcall(database.query, query_string)
If all is well, status would be true and result would be the normal result of the database.query() function. If there is an error, status would be false, and result would be the error message.
Give it a try and see if that helps.