Transaction is closed error

Hi, can anybody help me solve this one? I am getting the following ‘Transaction is closed’ error on a pushbutton actionPerformed event:

Here is my script:

==========
dbConn = “dbName”

table = event.source.parent.getComponent(“Table”)
data = table.data
line = data.getValueAt(table.selectedRow,“Row1”)
charge_no = data.getValueAt(table.selectedRow,“Row2”)

if system.gui.confirm(“Are you sure you want to delete the selected record?”):
system.db.runPrepUpdate(“DELETE FROM dbTable WHERE line = ? AND charge_no = ?”, [Row1], [Row2], dbConn)
system.db.refresh(event.source.parent.getComponent(‘Table’), “data”)
system.gui.messageBox(“Record item deleted”)

Here is the error message:

==========
Traceback (most recent call last):

File “event:actionPerformed”, line 9, in

java.lang.Exception: java.lang.Exception: Error executing system.db.runPrepUpdate(DELETE FROM dbTable WHERE Row1 = ? AND Row2 = ?, [4], [23], Database, false, false)

caused by Exception: Error executing system.db.runPrepUpdate(DELETE FROM dbTable WHERE line = ? AND charge_no = ?, [4], [23], dbName, false, false)
caused by GatewayException: Connection Error: Transaction “dbName” is closed.
caused by SQLException: Transaction “dbName” is closed.

Ignition v7.9.3 (b2017060210)
Java: Oracle Corporation 1.8.0_131

Thanks for any assistance.

The second parameter to system.db.runPrepUpdate() must be a list of the parameter values to substitute where you’ve placed question marks in the query. You have two parameters, but you’ve placed each value in its own list, messing up the following arguments to runPrepUpdate().
Replace:

[Row1], [Row2]

with:

[Row1, Row2]

so your values are in a single list. Side note: use triple-backquotes in your posts before and after script snippets to format them correctly. Instead of the lines of equal signs.

Many thanks, that fixed it!!! I don’t think I would have ever found that.

1 Like

In my case, I had switched from "system.db.runPrepUpdate" to "system.db.runUpdateQuery" and forgot to remove 'args' from my parameters.