Exception using transaction with Self Servicing template

Posts   
 
    
LloydM
User
Posts: 17
Joined: 05-Dec-2007
# Posted on: 04-Mar-2008 16:56:58   

Hello,

I'm getting a System.Exception {System.InvalidOperationException} when attempting to wrap the proccessing of some LLBLGen entities within a transaction.

The Inner Exception message states: "There is already an open DataReader associated with this Command which must be closed first."

The exception occurs during a lazy load fetch of an entity collection two levels beneath a parent LLBLGen entity. I'm overriding the OnFetchComplete() method in the first child entity to initialize a struct by looping through the second child entity collection.

I don't get the exception if I remove the transaction or I skip the code to initialize the struct in the first child entity's OnFetchComplete() method.

I've attached some code to assist with troubleshooting.

I'm using LLBLGen v2.5 Final.

Please advise.

Attachments
Filename File size Added on Approval
LLBLGen transaction issue.TXT 8,434 04-Mar-2008 16:57.16 Approved
goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 04-Mar-2008 17:26:28   

Please post your implementation of the OnFetchComplete() method so we can help you better.

I've did some research on your issue and it seems to be related with multithreading with the DataAccessAdapter object, so you probably are sharing the same Adapter in the OnFetchComplete().

The following threads might be of some help:

http://llblgen.com/tinyforum/Messages.aspx?ThreadID=644 http://llblgen.com/tinyforum/Messages.aspx?ThreadID=5892 http://llblgen.com/tinyforum/Messages.aspx?ThreadID=4431 http://llblgen.com/tinyforum/Messages.aspx?ThreadID=5381

LloydM
User
Posts: 17
Joined: 05-Dec-2007
# Posted on: 04-Mar-2008 17:48:56   

goose,

Thanks for your quick response, but I did include my implementation of the OnFetchComplete() method in the posted attachment.

I'm not creating any threads in my code and I'm using Self Servicing rather than the Adapter template, so any adapter sharing or multi threading is occurring within LLBLGen's libraries.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 05-Mar-2008 11:52:19   

attached wrote:

        // exception occurs here on first fetch of AlternatesRequestCompany entity's AlternatesRequestSubscriber collection entity
        foreach (AlternatesRequestCompanyEntity company in altRequest.AlternatesRequestCompany)
        {
          GenerateRates(altRequest, company);  //never get here
        }

Try not to fetch entities inside a transaction, and if you have to do so, then avoid lazy loading, i.e. use a PrefetchPath to fetch AlternatesRequestCompany related entities when fetching the AlternatesRequestCollection inside the GetRequestsToBeProcessed().

LloydM
User
Posts: 17
Joined: 05-Dec-2007
# Posted on: 05-Mar-2008 21:09:54   

Walaa,

My problem is making more sense to me now. The code I wrote in one entity's OnFetchComplete() method override included looping through a collection of that entity which in turn caused the error due to an internal call to create another data reader object in the current command's context. The issue cleared up once I took out the code.

I have another issue regarding transactions, but I'll start another post.

goose and Walaa,

Thanks again for your assistance!