Connection Manager And Multiple Data Readers

Connection Manager And Multiple Data Readers

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


MadGerbil posted on Friday, April 16, 2010

I allow users to save collections of data that are in the process of being edited. I have to support this because they deal with thousands of records which may take hours to edit and if they are interupted then they need to be able to save the work in progress and move onto other tasks. The records are saved in an editing table until the entire batch is valid and ready to be imported into live tables.

When the user opens the records I use a connection manager. The parent grabs a data reader and flips through each one creating child objects along the way. The problem occurs in the child object where a call to ValidationRules.CheckRules calls rules that open additional data readers on the same connection and the whole thing blows up.

Of course, normally one wouldn't check business rules when pulling the objects from a database, but alas, I cannot avoid doing it.

Should I:
1: Create a separate connection for the parent loading the objects?
2: Load the objects first and then flip though each child and check the rules?Recommendations?

RockfordLhotka replied on Friday, April 16, 2010

There are actually three options

  1. Use MARS (multiple active result sets)
  2. Create a separate connection for the parent loading the objects
  3. Load the objects first and flip through each child

I'm told that MARS has a perf hit, but I honestly don't know how big a hit it is relative to opening a separate connection. Certainly using MARS is easier (as I understand it) because I think you just change your connection string to turn on the feature.

But for my part I would probably go with multiple connections. The ConnectionManager.GetManager() method accepts a label parameter - each label corresponds to a different connection - so the multiple connection concept is already supported.

MadGerbil replied on Friday, April 16, 2010

Thank you for the thorough response.  

I like to run this stuff past the hound dogs at CSLA.NET because they often catch me missing something.

Copyright (c) Marimer LLC