Share via


Adding nesting options to DbConnectionScope.

I managed to squeeze in enough time to implement nesting options for the DbConnectionScope class.  My approach was to follow the nesting option pattern given by TransactionScope, so I added a DbConnectionScopeOptions enum with Required, RequiresNew and Suppress options.  The effect of these options is entirely contained within the DbConnectionScope constructor.

Required: If Current is null, makes this instance Current.  Otherwise, mark this instance as already Disposed.

RequiresNew: Same logic as original constructor -- save prior value of Current to restore later and makes this instance Current.

Suppress: Saves prior value of Current to restore on Dispose and set Current to null.

I've also added an option to search through prior scopes for a connection.  If you pass in true, the current stack of connection scopes will be searched.  False means only search the current scope.

I'd like to thank Jian Zeng from the ADO.Net test team and Jim Carley from the System.Transaction team for taking the time to review the code and provide feedback prior to posting.

DbConnectionScope.cs

Comments

  • Anonymous
    March 31, 2006
    Thanks for the good work Alazela, just what the System.Transactions LTM clan needed. Now I can dump my own data session implementation.
  • Anonymous
    April 19, 2006
    Any chance of a working example for a poor beginner like me  :-)

    Cheers,
    Steve C.
  • Anonymous
    May 04, 2006
    First, thanks for this greate piece of code...

    This code is safe in a ASP.NET context? See the link http://piers7.blogspot.com/2005/11/threadstatic-callcontext-and_02.html for background details for my question.