RunNamedQuery from Project Script Error

#1

Why when I run a named query in a project script I receive this?

I am running

system.db.runNamedQuery(“MyProject”, “MyQueries/NamedQuery”, {“parameter”:“myParameter”}, 0)

and I get this error

java.lang.Exception: java.sql.SQLException: Transaction "0" is closed.

When I run the same line of code on a button in a perspective view it works fine.

0 Likes

#2

What version are you using? The docs have not had time to catch up yet, but newer versions of Ignition (>=8.0.4) actually introduced transactional queries, so the 0 is being interpreted as the tx argument.

33%20PM

You have several options available to you, but what I recommend is simply modifying your code to:

system.db.runNamedQuery(“MyProject”, “MyQueries/NamedQuery”, {“parameter”:“myParameter”}, getKey=0)
0 Likes

#3

That is it. We are currently running 8.0.4. The manual does not say anything about “tx”, but if I do a ctrl+spacebar I see the tx parameter. Long story short always send named parameters and then you do not have to rely on the positioning to be correct.

0 Likes

#4

This is a pretty good practice yes, as it also helps for long-term maintenance.

0 Likes