Hi,
Ignition 8.0.3
I’m having trouble using transaction id from gateway scope.
I followed steps from the manual, if I run the script from the client the transaction work as expected, I can commit or rollback.
If the gateway run the script, I get error “Transaction id is closed”.
Anyone had trouble running Transacrion named query from gateway side?
I did put as parameter the project name and database connection for the gateway script as suggested by the manual.
As soon I’l be back home I will send my code.
Thanks for your time
Yes, please post your code. We tested both client and gateway scopes when adding this feature, so it should work.
Hi Kathy,
I rewrite my code and now it seems work both side, client and gateway.
Do you have any suggestion for me, on how to avoid this ?
tid = system.db.beginNamedQueryTransaction("DBDebug")
param = {"text": system.tag.read("[OpcTags]Text").value ,"date": system.date.now()}
if "gw" in caller :
system.db.runNamedQuery("DbName","Tid",param,tid)
system.db.commitTransaction(tid)
else :
system.db.runNamedQuery("Tid",param, tid)
system.db.commitTransaction(tid)
system.db.closeTransaction(tid)
For testing purpose I need to fire this script from client side before I can be confident and let It to be called by the gateway.
Can I do something in order to avoid writing 2 times every query like the script above?
Thanks for your time.
Ok i see.
So that code is working if executed from the script console, or by a tag value change script.
If I put same code on timer script, this error is been generated :
(despite the error, I find a new row been inserted in the db, so I guess the commit is working)
com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File "", line 1, in File "", line 43, in Go at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:362) at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.commitTransaction(AbstractDBUtilities.java:438) at jdk.internal.reflect.GeneratedMethodAccessor42.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.base/java.lang.reflect.Method.invoke(Unknown Source) java.lang.Exception: java.lang.Exception: Error executing system.db.commitTransaction()
at org.python.core.Py.JavaError(Py.java:552)
at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:362)
at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.commitTransaction(AbstractDBUtilities.java:438)
at jdk.internal.reflect.GeneratedMethodAccessor42.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:188)
at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction.__call__(ScriptManager.java:518)
at org.python.core.PyObject.__call__(PyObject.java:480)
at org.python.core.PyObject.__call__(PyObject.java:484)
at org.python.pycode._pyx90.Go$1(:47)
at org.python.pycode._pyx90.call_function()
at org.python.core.PyTableCode.call(PyTableCode.java:171)
at org.python.core.PyBaseCode.call(PyBaseCode.java:139)
at org.python.core.PyFunction.__call__(PyFunction.java:413)
at org.python.pycode._pyx89.f$0(:1)
at org.python.pycode._pyx89.call_function()
at org.python.core.PyTableCode.call(PyTableCode.java:171)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1614)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:761)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:716)
at com.inductiveautomation.ignition.common.script.TimerScriptTask.run(TimerScriptTask.java:88)
at java.base/java.util.TimerThread.mainLoop(Unknown Source)
at java.base/java.util.TimerThread.run(Unknown Source)
Caused by: org.python.core.PyException: Traceback (most recent call last): File "", line 1, in File "", line 43, in Go at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:362) at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.commitTransaction(AbstractDBUtilities.java:438) at jdk.internal.reflect.GeneratedMethodAccessor42.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.base/java.lang.reflect.Method.invoke(Unknown Source) java.lang.Exception: java.lang.Exception: Error executing system.db.commitTransaction()
... 25 common frames omitted
Caused by: java.lang.Exception: Error executing system.db.commitTransaction()
... 24 common frames omitted
java.lang.NullPointerException: null
I don’t understand what I’m missing sorry,
I may have misunderstood the rollback system at this point, please could someone help me understand why this code keep inserting a new row in my db?
Running this by the script console block the insert and rollback seams work just fine ,firing this on timer script always insert a new row.
Thanks
tid = system.db.beginNamedQueryTransaction("DBDebug")
param = {"text": system.tag.read("[Opc]Text").value ,"date": system.date.now()}
try :
if "gw" in caller :
system.db.runNamedQuery("dbName","Tid",param,tid)
a = 5/0
system.db.commitTransaction(tid)
else :
system.db.runNamedQuery("Tid",param, tid)
a = 5/0
system.db.commitTransaction(tid)
except :
system.db.rollbackTransaction(tid)
finally:
system.db.closeTransaction(tid)
You aren’t using the same connection name in system.db.beginNamedQueryTransaction as you are in system.db.runNamedQuery.
First parameter of system.db.runNamedQuery called from gateway is Project Name, not DBname.
At least from what I read on the ignition manual.
https://docs.inductiveautomation.com/display/DOC80/system.db.runNamedQuery
system.db.beginNamedQueryTransaction require Dbname, while for the transaction the db is specified inside the namedQuery,
Am I wrong?