Error executing script. Traceback (most recent call last): File "<tagevent:valueChanged>", line 19, in valueChanged

Hello everybody,

I am getting some issues writing data into a MySQL database, I am running my query into a Tag Event Script, some times the script run well but another it doesn’t and the issue log is the following
“Error executing script.
Traceback (most recent call last):
File “tagevent:valueChanged”, line 19, in valueChanged
at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:362)
at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runPrepUpdate(AbstractDBUtilities.java:258)
at jdk.internal.reflect.GeneratedMethodAccessor83.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.runPrepUpdate”

My script is the following

Does anybody knows why I am getting this error?

Can you post the full stack trace of the error?

This is the full log of the error

com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File "", line 19, in valueChanged at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:362) at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runPrepUpdate(AbstractDBUtilities.java:258) at jdk.internal.reflect.GeneratedMethodAccessor83.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.runPrepUpdate(INSERT INTO tblTiempos (NoTurno, NoModelo, NoBascula, TiempoTare, TiempoClamp, TiempoLlenado, Usuario, Fecha, TiempoCyD) VALUES (?,?,?,?,?,?,?,?,?), [1, 1, 1, Wed Dec 16 16:27:51 PST 2020, Wed Dec 16 16:41:39 PST 2020, 158, JMendoza, Wed Dec 16 16:41:39 PST 2020, 9], SQLUsrTiemposConnection, , false, false)

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.runPrepUpdate(AbstractDBUtilities.java:258)

at jdk.internal.reflect.GeneratedMethodAccessor83.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:524)

at org.python.core.PyObject.__call__(PyObject.java:515)

at org.python.core.PyObject.__call__(PyObject.java:519)

at org.python.pycode._pyx229.valueChanged$1(:19)

at org.python.pycode._pyx229.call_function()

at org.python.core.PyTableCode.call(PyTableCode.java:171)

at org.python.core.PyBaseCode.call(PyBaseCode.java:308)

at org.python.core.PyFunction.function___call__(PyFunction.java:471)

at org.python.core.PyFunction.__call__(PyFunction.java:466)

at org.python.core.PyFunction.__call__(PyFunction.java:461)

at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:822)

at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:806)

at com.inductiveautomation.ignition.gateway.tags.scripting.TagScriptManagerImpl$FunctionInvokerImpl.run(TagScriptManagerImpl.java:527)

at com.inductiveautomation.ignition.gateway.tags.scripting.events.AbstractTagScript.invoke(AbstractTagScript.java:34)

at com.inductiveautomation.ignition.gateway.tags.scripting.TagScriptManagerImpl$Task.invoke(TagScriptManagerImpl.java:476)

at com.inductiveautomation.ignition.gateway.tags.scripting.TagScriptManagerImpl$TagScriptDispatcher.run(TagScriptManagerImpl.java:439)

at com.inductiveautomation.ignition.common.execution.impl.BasicExecutionEngine$ThrowableCatchingRunnable.run(BasicExecutionEngine.java:518)

at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)

at java.base/java.util.concurrent.FutureTask.run(Unknown Source)

at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)

at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.base/java.lang.Thread.run(Unknown Source)

Caused by: org.python.core.PyException: Traceback (most recent call last): File "", line 19, in valueChanged at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:362) at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runPrepUpdate(AbstractDBUtilities.java:258) at jdk.internal.reflect.GeneratedMethodAccessor83.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.runPrepUpdate(INSERT INTO tblTiempos (NoTurno, NoModelo, NoBascula, TiempoTare, TiempoClamp, TiempoLlenado, Usuario, Fecha, TiempoCyD) VALUES (?,?,?,?,?,?,?,?,?), [1, 1, 1, Wed Dec 16 16:27:51 PST 2020, Wed Dec 16 16:41:39 PST 2020, 158, JMendoza, Wed Dec 16 16:41:39 PST 2020, 9], SQLUsrTiemposConnection, , false, false)

... 30 common frames omitted

Caused by: java.lang.Exception: Error executing system.db.runPrepUpdate(INSERT INTO tblTiempos (NoTurno, NoModelo, NoBascula, TiempoTare, TiempoClamp, TiempoLlenado, Usuario, Fecha, TiempoCyD) VALUES (?,?,?,?,?,?,?,?,?), [1, 1, 1, Wed Dec 16 16:27:51 PST 2020, Wed Dec 16 16:41:39 PST 2020, 158, JMendoza, Wed Dec 16 16:41:39 PST 2020, 9], SQLUsrTiemposConnection, , false, false)

... 29 common frames omitted

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Violation of PRIMARY KEY constraint 'PK_tblTiempos'. Cannot insert duplicate key in object 'dbo.tblTiempos'. The duplicate key value is (1, 1, 1, Dec 16 2020 4:27PM).

at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:256)

at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1621)

at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:592)

at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:522)

at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7194)

at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2930)

at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:248)

at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:223)

at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeUpdate(SQLServerPreparedStatement.java:471)

at org.apache.commons.dbcp2.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:136)

at org.apache.commons.dbcp2.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:136)

at com.inductiveautomation.ignition.gateway.datasource.SRConnectionWrapper$SRPreparedStatement.executeUpdate(SRConnectionWrapper.java:1016)

at com.inductiveautomation.ignition.gateway.datasource.SRConnectionWrapper.runPrepUpdate(SRConnectionWrapper.java:183)

at com.inductiveautomation.ignition.gateway.script.GatewayDBUtilities._runPrepStmt(GatewayDBUtilities.java:186)

at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runPrepUpdate(AbstractDBUtilities.java:256)

... 27 common frames omitted
type or paste code here

This is the key part of the error and why that particular script invocation didn’t work (violation of a primary key constraint):

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Violation of PRIMARY KEY constraint 'PK_tblTiempos'. Cannot insert duplicate key in object 'dbo.tblTiempos'. The duplicate key value is (1, 1, 1, Dec 16 2020 4:27PM).
1 Like

I solved the problem creating an extra key column into my DB with a number ID that is changing in each row, now my script is working well all times and storages the info correctly.

Thanks!