Issue with unclosed data reader  Topic is solved

Discussions relating to Jiwa 7 plugin development, and the Jiwa 7 API.

Issue with unclosed data reader

Postby indikad » Tue Oct 27, 2015 10:46 am

I appreciate if one of the developers can give me a hint where I can find a workaround or a fix for this issue.
In summary –
I have a plugin that acts on the sales quote window on save.
The event is - SalesQuote.SaveEnd

There is a lot of code - however the theory is simple. In this code I read the database in several different functions using a sql connection, command and a data reader.
Each function closes and disposes the data reader , command and the connection in its own finally block.

However :
After the second call to a certain function (getSalesQuoteLinesInventoryID) (that reads the database) – the next function call (to read the database) gives me the following error.
“there is already an open datareader associated with this command which must be closed”

As indicated above I close all objects. In addition I have spent a the whole day today trying to isolate any syntax errors that I cannot find.

Attached is the code if you could have a look. Attached also is the screenshot sequence of function calls and the last of which gives the error.
indikad
Frequent Contributor
Frequent Contributor
 
Posts: 182
Joined: Thu Jun 18, 2009 1:14 pm
Topics Solved: 2

Re: Issue with unclosed data reader

Postby Mike.Sheen » Tue Oct 27, 2015 3:47 pm

indikad wrote:Attached is the code if you could have a look. Attached also is the screenshot sequence of function calls and the last of which gives the error.


You forgot the attachment.
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: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: Issue with unclosed data reader  Topic is solved

Postby Mike.Sheen » Thu Oct 29, 2015 9:38 pm

The problem was resolved by the submitter, offline.

Turns out the problem was failure to use the using command to auto-dispose a SqlCommand.

You should always use using! i.e.:

Code: Select all
Using SQLCmd As SqlCommand = New SqlCommand(Sql, .SQLConnection, .SQLTransaction)
...
End Using
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: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 4 guests

cron