Page 1 of 1

New Transaction not allowed error on bulk inventories import

PostPosted: Tue Feb 14, 2023 8:44 am
by sameermoin
Hello Everyone,

I am using the Inventory SaveEnd event for creating a custom webhook event asynchronously so that it won't block the main thread and its works fine when I update or create an inventory from the inventory maintenance form but when I do a bulk import using the Jiwa import utility I am getting "New transaction is not allowed because there are other threads running in the session" error. I am just reading SOH, attribute groups, and custom fields using SQL queries and not updating anything.

Screenshot 2023-02-01 182520.jpg


I also attached the custom plugin with a CSV file.

Re: New Transaction not allowed error on bulk inventories im

PostPosted: Tue Feb 14, 2023 8:45 am
by sameermoin
Due to no limitation attaching the attribute template in the new comment.

Re: New Transaction not allowed error on bulk inventories im

PostPosted: Tue Feb 14, 2023 9:50 am
by SBarnes
Without taking too much of a look at the code, that error is caused by a reader being open whilst Jiwa tries to commit a transaction to the database, whilst it looks like all your code has finally blocks to close the readers but check these anyway, you have helper class calls that are marked as async which means you can't guarantee the timing of the calls I would suggest starting with making the code synchronous and see if that fixes it.

The other thing you can do is run SQL profiler to see if you can determine anything from the SQLs ahead of the commit that could cause the issue.

Re: New Transaction not allowed error on bulk inventories im

PostPosted: Tue Feb 14, 2023 10:56 am
by Mike.Sheen
sameermoin wrote:when I do a bulk import using the Jiwa import utility I am getting "New transaction is not allowed because there are other threads running in the session" error.


Thanks for supplying the plugin, sample import data and exported attribute data - I've downloaded these imported them and can repro your issue.

I'm just exploring your options and will post back here.

Re: New Transaction not allowed error on bulk inventories im  Topic is solved

PostPosted: Tue Feb 14, 2023 12:06 pm
by Mike.Sheen
Attached is a revised plugin that uses an ORMLite connection for the asynchronous reads you are performing.

I also removed the use of the Newtonsoft Json serialiser embedded reference and instead use the ServiceStack serialiser already shipped with Jiwa (it's a lot faster, too). Note that importing plugins won't ever delete references that were removed, so it would be best to delete your plugin, then import this modified one.

The ServiceStack OrmLite queries use the same connection string information as the application, but as it is a separate connection it won't interfere with the transactions in play by the Jiwa application during the import. It also handles a lot of the boilerplate code for you, so mapping a query result to a List<T> is automatic - so if you look at the code you'll find it is now a lot simpler and cleaner.

Re: New Transaction not allowed error on bulk inventories im

PostPosted: Wed Feb 15, 2023 6:02 am
by sameermoin
Hi Mike,

first, thank you so much for helping me.

Newtonsoft is outclassed as it has more flexibilities than others like ignoring the properties based on conditions when serializing or deserializing, handling multiple JSON cases, and much more. I need all these in my requirements. The plugin that I attached is just for demonstration, I am doing a lot of other stuff in the code.

Re: New Transaction not allowed error on bulk inventories im

PostPosted: Wed Feb 15, 2023 6:09 am
by sameermoin
SBarnes wrote:Without taking too much of a look at the code, that error is caused by a reader being open whilst Jiwa tries to commit a transaction to the database, whilst it looks like all your code has finally blocks to close the readers but check these anyway, you have helper class calls that are marked as async which means you can't guarantee the timing of the calls I would suggest starting with making the code synchronous and see if that fixes it.

The other thing you can do is run SQL profiler to see if you can determine anything from the SQLs ahead of the commit that could cause the issue.



Thanks for the suggestions.

It was working fine on the synchronous code but I want to keep that asynchronous due to good user experience. I tried many different approaches and checked each and every SQL query, and all seems good but ADO.NET method didn't work, now I updated my queries with ORMLite, and working fine so far.