Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Data / System / Data / SqlClient / SqlReferenceCollection.cs / 1305376 / SqlReferenceCollection.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //[....] //----------------------------------------------------------------------------- using System; using System.Data; using System.Data.Common; using System.Diagnostics; using System.Data.ProviderBase; namespace System.Data.SqlClient { sealed internal class SqlReferenceCollection : DbReferenceCollection { internal const int DataReaderTag = 1; private int _dataReaderCount; internal bool MayHaveDataReader { get { return (0 != _dataReaderCount); } } override public void Add(object value, int tag) { Debug.Assert(DataReaderTag == tag, "unexpected tag?"); Debug.Assert(value is SqlDataReader, "tag doesn't match object type: SqlDataReader"); _dataReaderCount++; base.AddItem(value, tag); } internal void Deactivate() { if (MayHaveDataReader) { base.Notify(0); _dataReaderCount = 0; } Purge(); } internal SqlDataReader FindLiveReader(SqlCommand command) { // if null == command, will find first live datareader // else will find live datareader assocated with the command if (MayHaveDataReader) { foreach (SqlDataReader dataReader in Filter(DataReaderTag)) { if ((null != dataReader) && !dataReader.IsClosed && ((null == command) || (command == dataReader.Command))) { return dataReader; } } } return null; } override protected bool NotifyItem(int message, int tag, object value) { Debug.Assert(0 == message, "unexpected message?"); Debug.Assert(DataReaderTag == tag, "unexpected tag?"); SqlDataReader rdr = (SqlDataReader)value; if (!rdr.IsClosed) { rdr.CloseReaderFromConnection (); } return false; // remove it from the collection } override public void Remove(object value) { Debug.Assert(value is SqlDataReader, "SqlReferenceCollection.Remove expected a SqlDataReader"); _dataReaderCount--; base.RemoveItem(value); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //[....] //----------------------------------------------------------------------------- using System; using System.Data; using System.Data.Common; using System.Diagnostics; using System.Data.ProviderBase; namespace System.Data.SqlClient { sealed internal class SqlReferenceCollection : DbReferenceCollection { internal const int DataReaderTag = 1; private int _dataReaderCount; internal bool MayHaveDataReader { get { return (0 != _dataReaderCount); } } override public void Add(object value, int tag) { Debug.Assert(DataReaderTag == tag, "unexpected tag?"); Debug.Assert(value is SqlDataReader, "tag doesn't match object type: SqlDataReader"); _dataReaderCount++; base.AddItem(value, tag); } internal void Deactivate() { if (MayHaveDataReader) { base.Notify(0); _dataReaderCount = 0; } Purge(); } internal SqlDataReader FindLiveReader(SqlCommand command) { // if null == command, will find first live datareader // else will find live datareader assocated with the command if (MayHaveDataReader) { foreach (SqlDataReader dataReader in Filter(DataReaderTag)) { if ((null != dataReader) && !dataReader.IsClosed && ((null == command) || (command == dataReader.Command))) { return dataReader; } } } return null; } override protected bool NotifyItem(int message, int tag, object value) { Debug.Assert(0 == message, "unexpected message?"); Debug.Assert(DataReaderTag == tag, "unexpected tag?"); SqlDataReader rdr = (SqlDataReader)value; if (!rdr.IsClosed) { rdr.CloseReaderFromConnection (); } return false; // remove it from the collection } override public void Remove(object value) { Debug.Assert(value is SqlDataReader, "SqlReferenceCollection.Remove expected a SqlDataReader"); _dataReaderCount--; base.RemoveItem(value); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- VirtualPathUtility.cs
- DataViewSetting.cs
- COM2PropertyDescriptor.cs
- Section.cs
- WindowsFormsHostPropertyMap.cs
- ReferenceEqualityComparer.cs
- HttpStreamFormatter.cs
- DataRecordObjectView.cs
- HuffModule.cs
- ResourceExpressionBuilder.cs
- DataConnectionHelper.cs
- EdmConstants.cs
- AnnouncementSendsAsyncResult.cs
- ConstraintCollection.cs
- ToolStripArrowRenderEventArgs.cs
- SystemResourceKey.cs
- OverlappedAsyncResult.cs
- SlipBehavior.cs
- WsatConfiguration.cs
- VisualBasicImportReference.cs
- PersonalizationEntry.cs
- ErrorWebPart.cs
- UInt32.cs
- SignatureResourcePool.cs
- BaseProcessor.cs
- UriTemplatePathSegment.cs
- SerTrace.cs
- ProfileModule.cs
- WizardStepBase.cs
- BasicExpressionVisitor.cs
- TextParaClient.cs
- TemplateGroupCollection.cs
- _NativeSSPI.cs
- FormParameter.cs
- CapiNative.cs
- WeakHashtable.cs
- IdentitySection.cs
- DispatcherObject.cs
- Regex.cs
- ContractMethodInfo.cs
- PathGeometry.cs
- FixedStringLookup.cs
- TableLayoutPanelCellPosition.cs
- EventlogProvider.cs
- PassportIdentity.cs
- ShapingEngine.cs
- AssociatedControlConverter.cs
- input.cs
- LexicalChunk.cs
- HtmlInputReset.cs
- __Filters.cs
- ClientBuildManagerCallback.cs
- Set.cs
- DrawingContext.cs
- SystemIPGlobalStatistics.cs
- SynthesizerStateChangedEventArgs.cs
- ZipIOZip64EndOfCentralDirectoryLocatorBlock.cs
- ECDiffieHellman.cs
- EntitySetBase.cs
- TablePattern.cs
- NativeMethods.cs
- CFStream.cs
- SecurityPermission.cs
- SymmetricAlgorithm.cs
- Normalization.cs
- bindurihelper.cs
- __Filters.cs
- Utilities.cs
- OutputScopeManager.cs
- ProcessHost.cs
- ExtendedPropertyInfo.cs
- CqlBlock.cs
- MD5.cs
- ReadWriteObjectLock.cs
- X509Extension.cs
- WebScriptMetadataMessageEncoderFactory.cs
- TextTreeUndoUnit.cs
- TableParaClient.cs
- XmlAttributes.cs
- MdbDataFileEditor.cs
- TextProperties.cs
- PassportAuthenticationEventArgs.cs
- Stack.cs
- OrthographicCamera.cs
- XmlEntity.cs
- WindowsSysHeader.cs
- ErrorFormatterPage.cs
- EntityDataSourceSelectingEventArgs.cs
- NameValueCollection.cs
- StoreItemCollection.cs
- WebPartTransformer.cs
- AssemblyAssociatedContentFileAttribute.cs
- EntityDataSourceChangingEventArgs.cs
- FormatConvertedBitmap.cs
- NavigationProperty.cs
- SiteMapProvider.cs
- Adorner.cs
- OLEDB_Enum.cs
- ListDictionaryInternal.cs
- ParameterCollectionEditor.cs