New Transaction not allowed error on bulk inventories import  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

New Transaction not allowed error on bulk inventories import

Postby sameermoin » Tue Feb 14, 2023 8:44 am

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.
Attachments
Plugin BulkImportTest.xml
(961.71 KiB) Downloaded 69 times
importItems.csv
(2.68 KiB) Downloaded 71 times
sameermoin
Regular Contributor
Regular Contributor
 
Posts: 75
Joined: Wed Jun 15, 2022 4:02 am
Topics Solved: 1

Re: New Transaction not allowed error on bulk inventories im

Postby sameermoin » Tue Feb 14, 2023 8:45 am

Due to no limitation attaching the attribute template in the new comment.
Attachments
Inventory Group Attribute Product Metadata.xml
(9.96 KiB) Downloaded 71 times
sameermoin
Regular Contributor
Regular Contributor
 
Posts: 75
Joined: Wed Jun 15, 2022 4:02 am
Topics Solved: 1

Re: New Transaction not allowed error on bulk inventories im

Postby SBarnes » Tue Feb 14, 2023 9:50 am

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.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: New Transaction not allowed error on bulk inventories im

Postby Mike.Sheen » Tue Feb 14, 2023 10:56 am

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.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

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

Postby Mike.Sheen » Tue Feb 14, 2023 12:06 pm

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.
Attachments
Plugin BulkImportTest V2.xml
(18.68 KiB) Downloaded 67 times
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: New Transaction not allowed error on bulk inventories im

Postby sameermoin » Wed Feb 15, 2023 6:02 am

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.
Last edited by sameermoin on Wed Feb 15, 2023 6:33 am, edited 1 time in total.
sameermoin
Regular Contributor
Regular Contributor
 
Posts: 75
Joined: Wed Jun 15, 2022 4:02 am
Topics Solved: 1

Re: New Transaction not allowed error on bulk inventories im

Postby sameermoin » Wed Feb 15, 2023 6:09 am

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.
sameermoin
Regular Contributor
Regular Contributor
 
Posts: 75
Joined: Wed Jun 15, 2022 4:02 am
Topics Solved: 1


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 32 guests