Possible to fetch and update data while inserting?

Possible to fetch and update data while inserting?

Old forum URL: forums.lhotka.net/forums/t/3594.aspx


Remoray posted on Wednesday, September 26, 2007

I have some business logic I would like to execute prior to/while saving a BusinessObject. I tried to to this in the DataPortal_Insert() method.

Unfortunately, because of "[Transactional(TransactionalTypes.TransactionScope)]" I cannot use any other calls to DataPortal_Fetch(), because these lead to "System.InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first."

Is there any other way around this besides using the logic on the server (say e.g. stored procedures)? Plus: I would, of course, wanted the other calls/updates to run in this transaction, too... but these updates are not really child objects of the object I am trying to persist.

TIA,
Remoray

 

ajj3085 replied on Wednesday, September 26, 2007

Hi,

You can read in your DP_I or DP_U, but the same rules apply to datareaders; only one can be open at a time.  So you'll have to rework your code around this.  You could also use MARS in your connection string, but I'm not sure what other changes that would introduce.  MARS = Multiple Active Result Sets.

Remoray replied on Friday, September 28, 2007

ajj3085:
Hi,

You can read in your DP_I or DP_U, but the same rules apply to datareaders; only one can be open at a time.  So you'll have to rework your code around this.  You could also use MARS in your connection string, but I'm not sure what other changes that would introduce.  MARS = Multiple Active Result Sets.

Thank you, I will have to rework the code then... ;-)

Curelom replied on Wednesday, September 26, 2007

You may try removing [Transactional(TransactionalTypes.TransactionScope)] from the fetch method.  It is seldom needed for a fetch.

ajj3085 replied on Wednesday, September 26, 2007

I think the means the Transactional is on the DP_I or DP_U.

ReadOnlyChild replied on Friday, September 28, 2007

Remoray:

I have some business logic I would like to execute prior to/while saving a BusinessObject. I tried to to this in the DataPortal_Insert() method.

Unfortunately, because of "[Transactional(TransactionalTypes.TransactionScope)]" I cannot use any other calls to DataPortal_Fetch(), because these lead to "System.InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first."

Is there any other way around this besides using the logic on the server (say e.g. stored procedures)? Plus: I would, of course, wanted the other calls/updates to run in this transaction, too... but these updates are not really child objects of the object I am trying to persist.

TIA,
Remoray

...maybe work on using another method that cascades the connection or transaction so it can be shared but use a new command...

private... DP_Fetch(criteria)
using (connection with transaction conn){
    using(command cmd){
        // to stuff
        doMoreStuff(conn);
    }
}

 

Copyright (c) Marimer LLC