SqlClient exception


The exception reads

************** Exception Text **************
System.InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first.
at System.Data.SqlClient.SqlInternalConnectionTds.ValidateConnectionForExecute(SqlCommand command)
at System.Data.SqlClient.SqlInternalTransaction.Rollback()
at System.Data.SqlClient.SqlTransaction.Rollback()
at Chili.Opf3.Storages.SqlTransactionBase.Rollback() in C:\Users\Christian\Documents\Visual Studio 2008\Projects\Chili\Opf3\Source\Chili.Opf3\Storages\SqlTransactionBase.cs:line 96
at Chili.Opf3.Storages.MsSql.MsSqlTransaction.Rollback() in C:\Users\Christian\Documents\Visual Studio 2008\Projects\Chili\Opf3\Source\Chili.Opf3\Storages\MsSql\MsSqlTransaction.cs:line 137
at Chili.Opf3.Storages.Transaction.Dispose() in C:\Users\Christian\Documents\Visual Studio 2008\Projects\Chili\Opf3\Source\Chili.Opf3\Storages\Transaction.cs:line 228
at CAE.Evento.Save(StoreOperation op) in C:\CentralAtencionEmergencias\DataModel\Evento.cs:line 105
at CAE.Evento.Save() in C:\CentralAtencionEmergencias\DataModel\Evento.cs:line 112

The code where the exception throws is
public void Save( StoreOperation op )
            ObjectContext context = PostesSQLSession.ObjectContext;

            Aud_Evento aud = new Aud_Evento( this );

            if (op == StoreOperation.X)
                op = isNew ? StoreOperation.A : StoreOperation.M;

            aud.Operacion = op.ToString();

            try {
                using (Transaction t = context.StartTransaction()) {
                    context.PersistChanges<Evento>( this );
                    context.PersistChanges<Aud_Evento>( aud );
                    if ( this.UsuarioRuta != null ) 
                        this.UsuarioRuta.Store(op, context );
                    foreach (Vehiculo v in this.Vehiculo)
                        v.Store( op, context );
                    foreach (Intervencion i in this.Intervencion)
                        i.Store( op, context );
                    foreach (Comunicacion c in this.Comunicacion)
                        c.Store( op, context );
            catch (Exception e) {


The exception throws when executing the very first PersistChange. It was an update of the "Evento" instance.

We are developing this application, and the code worked OK several times, both with completely new instances and updating some parts of the graph. 

Cannot guess what is happening. 




marcelo48 wrote Sep 16, 2013 at 10:51 PM

Moreover, I traced the exception to the RelationsManager.PersistRelated method, specifically
the objectHolder.PersistChanges(_context, persistDepth); call
if (info.RelationAttribute.PersistRelationship == persistRelationship)
                    if (persistentOperation == PersistentOperations.Insert && (info.RelationAttribute.PersistBehaviours & PersistBehaviours.DontInsert) != 0)
                    else if (persistentOperation == PersistentOperations.Update && (info.RelationAttribute.PersistBehaviours & PersistBehaviours.DontUpdate) != 0)
                    // Get the objectHolder.
                    ObjectHolderBase objectHolder = info.GetObjectHolder(obj);
                    // Skip if the holder is null.
                    if (objectHolder == null)

                    objectHolder.PersistChanges(_context, persistDepth);