# SQL script cause database to lock block

**URL:** <https://forum.inductiveautomation.com/t/sql-script-cause-database-to-lock-block/79246>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [September 16, 2023, 1:37am UTC](https://forum.inductiveautomation.com/t/sql-script-cause-database-to-lock-block/79246 "2023-09-16T01:37:24Z")\
**Posts on this page:** 1\
**Showing post:** 29

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [September 18, 2023, 4:52pm UTC](https://forum.inductiveautomation.com/t/sql-script-cause-database-to-lock-block/79246/29 "2023-09-18T16:52:11Z")

</div>

> [@Eugene49](#):
>
> including the Begin and Commit statement contained in the NamedQuery..
> 
> I have my try-except, commit-rollback logic in place.

If you are not using Ignition to create the transaction, then Ignition will not be able to rollback the transaction. Don't do this. Create the transaction in ignition with the rollback/commit logic in Ignition, or do it in a stored procedure if you want it to be purely handled by the DB. Don't do it in both places.

You said you are using `system.db.beginNamedQueryTransaction()` if that is the case, then you are effectively wrapping a transaction with a transaction (not good).

Multiple queries inside of a named query is just asking for trouble (Even if it works currently). On top of that it makes it difficult to troubleshoot should it come to that. Split them out completely. If for some reason you insist on multiple statements being executed in one call then you should use a stored procedure.

Use `java.lang.Throwable` to catch errors.

> [@system.db.runUpdateQuery Exception Handling](https://forum.inductiveautomation.com/t/system-db-runupdatequery-exception-handling/68237/2):
>
> Normal jython try: -- except: won't trap java exceptions. You often need two except: clauses, the first being except java.lang.Throwable, t: or similar. Some [related discussions](https://forum.inductiveautomation.com/search?q=Throwable%20%40pturmel). Note that when catching such exceptions in Vision Client scope or Designer scope, the real SQL exception is not available--it won't serialize and the JDBC classes don't exist in those scopes anyways.

---

_[View the full topic](https://forum.inductiveautomation.com/t/sql-script-cause-database-to-lock-block/79246)._
