I am using 7.9 ignition version I am getting dead lock error please could tell where is wrong since this happen weekly or monthly how we can avoid the error

if system.tag.read('[default]M3/Communication_OK').value == 1:
#Get all the finished injectors from EOL
kitSN_DS = system.db.runQuery("""SELECT DISTINCT trace.KITSN FROM [XPI_INJ_TRACE].[dbo].[T_INJ_TRACEABILITY] trace
INNER JOIN [XPI_INJ_TRACE].[dbo].[T_INJ_ASSEMBLY] assambly on trace.ID_TEST = assambly.ID_TEST and trace.KITSN = assambly.KITSN
WHERE trace.KITSN IN (SELECT KITSN FROM KITSN_MAPPING WHERE D_OK = 0) AND trace.kitsn not in (SELECT kitsn FROM [XPI_INJ_TRACE].[dbo].[T_INJ_TRACEABILITY] WHERE id_test = 'NEW') AND not trace.KITSN = 'SALVAGE' AND NOT trace.INJSN IS NULL AND NOT assambly.TEST_PASS IS NULL
""")

for row in kitSN_DS:
kitSN = row[0]
call = system.db.createSProcCall("writeEOLQualityCheck") #Set correct stored procedure
call.registerInParam(1, system.db.NVARCHAR, kitSN) #Send the correct kitSN number to the stored procedure

	system.db.execSProcCall(call) #Run the Stored Procedure
	
	XMLdata = call.getResultSet().getValueAt(0, 0) #Get the returned XML-string from Stored Procedure

	try:

		post_return = system.net.httpPost("http://SESOG1216.global.scd.xxx.com:8126", "text/xml", XMLdata)
	except:
		post_return = 'Failed'
	
	if post_return.find('The request was succesfully processed') > 0: #Good response back from M3 
		shared.Log_Handler.WriteLog('httpPost','D_EOLQualityCheck',XMLdata) #Write the transfered data to database for traceability
		system.db.runPrepUpdate("UPDATE KITSN_MAPPING SET D_OK = 1 WHERE KITSN = ?", [kitSN],'XPI')
	elif post_return == 'Failed': #Communication crashed
		system.tag.write('M3/Communication_OK',0)
		break
	else: #Communication ok, but faulty response from M3
		shared.Log_Handler.WriteLog('httpPost','D_EOLQualityCheck','Not succefully processed from M3') #Not succefully processed from M3

Please format your code using triple backticks to make it easier to read.

# like this

Can you copy and paste the whole error stack?

First thing that sticks out to me - looks like you are running this script on a 60 second timer. Does it actually complete in less than 60 seconds typically? Might want to confirm that / test how long it takes.

I do see one of the caused by: lines references a query and a deadlock scenario within your db so I don’t know that this is an ignition problem and instead a SQL problem.

3 Likes

at org.python.core.Py.JavaError(Py.java:495)

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 sun.reflect.GeneratedMethodAccessor37.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at org.python.core.PyReflectedFunction.call(PyReflectedFunction.java:186)

at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction.call(ScriptManager.java:431)

at org.python.core.PyObject.call(PyObject.java:422)

at org.python.core.PyObject.call(PyObject.java:426)

at org.python.pycode._pyx99.f$0(:8)

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

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

at org.python.core.PyCode.call(PyCode.java:18)

at org.python.core.Py.runCode(Py.java:1275)

at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:636)

at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:603)

at com.inductiveautomation.ignition.common.script.TimerScriptTask.run(TimerScriptTask.java:88)

at java.util.TimerThread.mainLoop(Unknown Source)

at java.util.TimerThread.run(Unknown Source)

Caused by: org.python.core.PyException: Traceback (most recent call last): File "", line 25, in 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 sun.reflect.GeneratedMethodAccessor37.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) java.lang.Exception: java.lang.Exception: Error executing system.db.runPrepUpdate(UPDATE KITSN_MAPPING SET D_OK = 1 WHERE KITSN = ?, [260191472], XPI, , false, false)

... 20 common frames omitted

Caused by: java.lang.Exception: Error executing system.db.runPrepUpdate(UPDATE KITSN_MAPPING SET D_OK = 1 WHERE KITSN = ?, [260191472], XPI, , false, false)

... 19 common frames omitted

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Transaction (Process ID 61) was deadlocked on lock | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction.

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

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

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

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

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

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

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

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

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

at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:102)

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

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

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

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

... 17 common frames omitted

Logger:
I
...com.inductiveautomation.ignition.gateway Time:
20Jan2026 07:03:31
Message:

duplicate message

"""
if system.tag.read('[default]M3/Communication_OK').value == 1:
#Get all the finished injectors from EOL
kitSN_DS = system.db.runQuery("""SELECT DISTINCT trace.KITSN FROM [XPI_INJ_TRACE].[dbo].[T_INJ_TRACEABILITY] trace
INNER JOIN [XPI_INJ_TRACE].[dbo].[T_INJ_ASSEMBLY] assambly on trace.ID_TEST = assambly.ID_TEST and trace.KITSN = assambly.KITSN
WHERE trace.KITSN IN (SELECT KITSN FROM KITSN_MAPPING WHERE D_OK = 0) AND trace.kitsn not in (SELECT kitsn FROM [XPI_INJ_TRACE].[dbo].[T_INJ_TRACEABILITY] WHERE id_test = 'NEW') AND not trace.KITSN = 'SALVAGE' AND NOT trace.INJSN IS NULL AND NOT assambly.TEST_PASS IS NULL
""")
#Go through all the injectors and send the data to M3, then delete it from temporary table in SCADA (KITSN_MAPPING)
for row in kitSN_DS:
kitSN = row[0]
call = system.db.createSProcCall("writeEOLQualityCheck") #Set correct stored procedure
call.registerInParam(1, system.db.NVARCHAR, kitSN) #Send the correct kitSN number to the stored procedure

	system.db.execSProcCall(call) #Run the Stored Procedure
	
	XMLdata = call.getResultSet().getValueAt(0, 0) #Get the returned XML-string from Stored Procedure

	try:
		#post_return = system.net.httpPost("http://sesoco3811.global.scd.xxx.com:8126", "text/xml", XMLdata)
		post_return = system.net.httpPost("http://SESOG1216.global.scd.xxx.com:8126", "text/xml", XMLdata)
	except:
		post_return = 'Failed'
	
	if post_return.find('The request was succesfully processed') > 0: #Good response back from M3 
		shared.Log_Handler.WriteLog('httpPost','D_EOLQualityCheck',XMLdata) #Write the transfered data to database for traceability
		system.db.runPrepUpdate("UPDATE KITSN_MAPPING SET D_OK = 1 WHERE KITSN = ?", [kitSN],'XPI')
	elif post_return == 'Failed': #Communication crashed
		system.tag.write('M3/Communication_OK',0)
		break
	else: #Communication ok, but faulty response from M3
		shared.Log_Handler.WriteLog('httpPost','D_EOLQualityCheck','Not succefully processed from M3') #Not succefully processed from M3

""" code I have to avoid the duplicate d message

60 sec

Is your code running on the gateway scope and on just one gateway?

What version of SQL Server?

I suspect this is an issue in how you’re interfacing with SQL server and it might be caused by multiple clients hitting the same database.

It might be SGAM contention. I think you’re getting an SGAM lock when you do the “UPDATE WHERE NOT IN” Statement. If that code executes from multiple clients before one of them finishes and you only have 1 ldf file configured on your database you will get an SGAM contention and possibly a deadlock. This could also happen if your code executes again before the first execution’s lock is lifted.

You can increase the number of SGAM locks your database can have by adding log files because you get 1 SGAM lock per log file. Research this before doing it so the new ldf files are configured correctly. It’s generally good to have 1 per CPU core on your db server. Newer versions of SQL Server do this automatically when you make a database. Older versions just created 1 ldf file.

Look into SGAM contention to get some diagnostic queries you can run to confirm or rule out an SGAM contention issue.

1 Like