# Named Query Deadlocked

**URL:** <https://forum.inductiveautomation.com/t/named-query-deadlocked/34155>\
**Category:** Ignition\
**Created:** [April 23, 2020, 1:17pm UTC](https://forum.inductiveautomation.com/t/named-query-deadlocked/34155 "2020-04-23T13:17:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![wschauer](https://avatars.discourse-cdn.com/v4/letter/w/ecccb3/32.png) [@wschauer](https://forum.inductiveautomation.com/u/wschauer)\
**Post date:** [April 23, 2020, 1:17pm UTC](https://forum.inductiveautomation.com/t/named-query-deadlocked/34155/1 "2020-04-23T13:17:25Z")

</div>

I have a barcode scanner attached to a PLC which we use to scan 3 separate barcodes for each transaction. We then have 3 separate tags in the PLC to act as a buffer to take in each barcode and then these trigger tag change scripts in ignition.  
Each tag change script runs a named query which returns information on how the machine should run depending on the barcode.  
we are getting errors if the barcodes are scanned quickly though, we get a transaction deadlock error with the named query(see below).

Is there a simple way to build a queue for these named queries? I was thinking about trying to use the object as part of the named query so i can start the next named query when when the previous one has started but then i end up not being able to use the tag change script to trigger the queries.  
Thanks,

> ava.lang.Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Transaction (Process ID 110) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 23, 2020, 1:59pm UTC](https://forum.inductiveautomation.com/t/named-query-deadlocked/34155/2 "2020-04-23T13:59:41Z")

</div>

That almost invariably means your query is doing something bad. AB-BA deadlock bad. You should not be papering over it with a queue. Your DB should be naturally interleaving these queries.

---

<div class="post-metadata">

**Author:** ![wschauer](https://avatars.discourse-cdn.com/v4/letter/w/ecccb3/32.png) [@wschauer](https://forum.inductiveautomation.com/u/wschauer)\
**Post date:** [April 23, 2020, 2:13pm UTC](https://forum.inductiveautomation.com/t/named-query-deadlocked/34155/3 "2020-04-23T14:13:32Z")

</div>

The named query is pretty simple

INSERT INTO BarcodeData (Equipment, Barcode, Flag, ScanDate) VALUES (:Equipment, :Barcode, :Flag, :ScanDate)

would this be something that needs adjusting in the DB?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 23, 2020, 2:15pm UTC](https://forum.inductiveautomation.com/t/named-query-deadlocked/34155/4 "2020-04-23T14:15:23Z")

</div>

I’m going to guess there is a complicated trigger firing in the DB upon insert, and there’s an AB-BA deadlock inside that (which is a form of stored procedure). So yes, you need help from your DBA.

---

<div class="post-metadata">

**Author:** ![wschauer](https://avatars.discourse-cdn.com/v4/letter/w/ecccb3/32.png) [@wschauer](https://forum.inductiveautomation.com/u/wschauer)\
**Post date:** [April 23, 2020, 2:16pm UTC](https://forum.inductiveautomation.com/t/named-query-deadlocked/34155/5 "2020-04-23T14:16:54Z")

</div>

Ah ok, there may be… I left that to our DB administrator in IT. I will follow up with him. Thanks for the help
