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
- DataTableTypeConverter.cs
- EllipticalNodeOperations.cs
- DashStyles.cs
- QueryRewriter.cs
- RepeaterItem.cs
- WorkflowIdleElement.cs
- XmlSchemaInclude.cs
- SafeCoTaskMem.cs
- Win32PrintDialog.cs
- RtType.cs
- SystemDropShadowChrome.cs
- EntityContainer.cs
- TableRow.cs
- XPathSingletonIterator.cs
- WindowsSysHeader.cs
- PointAnimation.cs
- WebPartConnection.cs
- ReservationCollection.cs
- TableHeaderCell.cs
- XXXOnTypeBuilderInstantiation.cs
- SecurityAlgorithmSuite.cs
- ButtonBaseAdapter.cs
- SmiMetaDataProperty.cs
- AssociationType.cs
- Item.cs
- AdPostCacheSubstitution.cs
- SmiEventSink_DeferedProcessing.cs
- TemplateBindingExpression.cs
- ImpersonationOption.cs
- UndoUnit.cs
- GradientStop.cs
- UniformGrid.cs
- MemberCollection.cs
- StoryFragments.cs
- ProtocolsSection.cs
- ItemAutomationPeer.cs
- ReliabilityContractAttribute.cs
- Icon.cs
- NavigationService.cs
- RectConverter.cs
- AllowedAudienceUriElement.cs
- SourceItem.cs
- ResXResourceSet.cs
- OleDbConnectionPoolGroupProviderInfo.cs
- ContentType.cs
- PopOutPanel.cs
- CharacterBuffer.cs
- AmbiguousMatchException.cs
- Matrix3D.cs
- ArraySortHelper.cs
- ExtendedPropertyCollection.cs
- SoapObjectWriter.cs
- SchemaExporter.cs
- RoleGroupCollectionEditor.cs
- DataContext.cs
- DbProviderSpecificTypePropertyAttribute.cs
- WindowsHyperlink.cs
- EventKeyword.cs
- DbDataAdapter.cs
- Clock.cs
- TabControl.cs
- UInt16.cs
- Fonts.cs
- CacheManager.cs
- EntityDataSourceContainerNameConverter.cs
- SqlProviderManifest.cs
- PointHitTestResult.cs
- SerTrace.cs
- HtmlElementEventArgs.cs
- ArgumentException.cs
- ValuePattern.cs
- KnownIds.cs
- QueuePathDialog.cs
- BitmapEffectGeneralTransform.cs
- RemoteWebConfigurationHost.cs
- Rect3D.cs
- DataControlLinkButton.cs
- ListItemConverter.cs
- EmbeddedObject.cs
- EncryptedPackage.cs
- Rect.cs
- UmAlQuraCalendar.cs
- XmlReflectionImporter.cs
- ActiveXSite.cs
- UseAttributeSetsAction.cs
- MatrixIndependentAnimationStorage.cs
- Property.cs
- localization.cs
- HashAlgorithm.cs
- BufferedReadStream.cs
- Utilities.cs
- CodeArrayIndexerExpression.cs
- _RequestLifetimeSetter.cs
- Collection.cs
- DataGridLinkButton.cs
- ImmutableObjectAttribute.cs
- ChameleonKey.cs
- basecomparevalidator.cs
- GridViewColumn.cs
- Utils.cs