Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- IdentityReference.cs
- Divide.cs
- XmlNodeChangedEventManager.cs
- FormViewPagerRow.cs
- RouteParser.cs
- sortedlist.cs
- SemanticKeyElement.cs
- Win32SafeHandles.cs
- PersonalizationProviderHelper.cs
- GroupBoxRenderer.cs
- IHttpResponseInternal.cs
- DbInsertCommandTree.cs
- Serializer.cs
- DataControlFieldCollection.cs
- ReceiveActivityDesigner.cs
- CollectionViewGroupRoot.cs
- RoamingStoreFileUtility.cs
- Rect3DValueSerializer.cs
- SelectedGridItemChangedEvent.cs
- ActiveXHost.cs
- ExtensionSimplifierMarkupObject.cs
- KeyEvent.cs
- DataGridViewControlCollection.cs
- Stack.cs
- EntityDataSourceEntitySetNameItem.cs
- ServerValidateEventArgs.cs
- HostingEnvironment.cs
- DbFunctionCommandTree.cs
- InstanceDescriptor.cs
- CacheSection.cs
- Rules.cs
- DeclarativeCatalogPart.cs
- XPathConvert.cs
- NumericPagerField.cs
- StateDesigner.cs
- NumberSubstitution.cs
- DataViewManager.cs
- ToolStripContainer.cs
- PropertyMetadata.cs
- PrinterResolution.cs
- SerialStream.cs
- SiteMembershipCondition.cs
- LiteralControl.cs
- SqlVisitor.cs
- IISMapPath.cs
- ExpressionEditorAttribute.cs
- SafeRightsManagementQueryHandle.cs
- GlyphInfoList.cs
- PowerModeChangedEventArgs.cs
- UrlMappingsSection.cs
- ContextConfiguration.cs
- HtmlEmptyTagControlBuilder.cs
- Keywords.cs
- BinaryWriter.cs
- CustomValidator.cs
- Hex.cs
- SmiContext.cs
- AtomServiceDocumentSerializer.cs
- EventManager.cs
- FontStretchConverter.cs
- OdbcDataAdapter.cs
- FontEmbeddingManager.cs
- MetadataCacheItem.cs
- AnalyzedTree.cs
- ListenerTraceUtility.cs
- IpcPort.cs
- HtmlLabelAdapter.cs
- CalculatedColumn.cs
- MenuItemBinding.cs
- ObjectDisposedException.cs
- Itemizer.cs
- Font.cs
- ReliableSessionBindingElementImporter.cs
- AvtEvent.cs
- DataFieldConverter.cs
- GenerateHelper.cs
- MDIWindowDialog.cs
- XmlNavigatorStack.cs
- SchemaImporterExtensionElement.cs
- EventListener.cs
- XmlAtomErrorReader.cs
- ZoneMembershipCondition.cs
- Pkcs7Recipient.cs
- ScaleTransform.cs
- DropDownButton.cs
- NonBatchDirectoryCompiler.cs
- ResolveCriteria11.cs
- Parser.cs
- ClickablePoint.cs
- PathSegmentCollection.cs
- MetadataArtifactLoaderComposite.cs
- IteratorFilter.cs
- OleDbMetaDataFactory.cs
- ScrollBarAutomationPeer.cs
- SessionStateSection.cs
- __Error.cs
- _OverlappedAsyncResult.cs
- MSAAWinEventWrap.cs
- FloaterParagraph.cs
- selecteditemcollection.cs