Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / Data / System / Data / SqlClient / SqlReferenceCollection.cs / 1 / 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
- TreeNodeClickEventArgs.cs
- OdbcCommand.cs
- TCPListener.cs
- DataException.cs
- SR.Designer.cs
- CleanUpVirtualizedItemEventArgs.cs
- RadioButtonStandardAdapter.cs
- XmlSerializerNamespaces.cs
- PresentationTraceSources.cs
- SecureStringHasher.cs
- WebEventTraceProvider.cs
- HatchBrush.cs
- TraceContextRecord.cs
- XmlSchemaRedefine.cs
- StylusPointProperties.cs
- ColumnTypeConverter.cs
- GridItem.cs
- ApplicationTrust.cs
- SafeNativeMethods.cs
- DataDesignUtil.cs
- ZoomPercentageConverter.cs
- Shape.cs
- QuerySetOp.cs
- PagedDataSource.cs
- Accessors.cs
- TextRangeAdaptor.cs
- TokenBasedSet.cs
- ValidationErrorCollection.cs
- ArgumentException.cs
- JsonFormatMapping.cs
- ContentFilePart.cs
- RuleInfoComparer.cs
- IncrementalHitTester.cs
- PolicyManager.cs
- Rfc2898DeriveBytes.cs
- ReceiveMessageAndVerifySecurityAsyncResultBase.cs
- DoWhileDesigner.xaml.cs
- COM2PropertyBuilderUITypeEditor.cs
- InlinedAggregationOperatorEnumerator.cs
- ConnectionManagementElement.cs
- RuntimeEnvironment.cs
- RequestTimeoutManager.cs
- SessionStateModule.cs
- PointIndependentAnimationStorage.cs
- InstanceView.cs
- HTMLTextWriter.cs
- SpellerStatusTable.cs
- TraceUtility.cs
- LineGeometry.cs
- XmlNotation.cs
- SectionInput.cs
- Byte.cs
- PropertyGrid.cs
- HttpVersion.cs
- StylusButtonEventArgs.cs
- AncestorChangedEventArgs.cs
- dsa.cs
- PersonalizableAttribute.cs
- LocatorGroup.cs
- MsmqMessageSerializationFormat.cs
- BufferedReadStream.cs
- IisTraceWebEventProvider.cs
- SubMenuStyleCollection.cs
- MemberMemberBinding.cs
- XmlUnspecifiedAttribute.cs
- OrderedDictionaryStateHelper.cs
- Pair.cs
- UIInitializationException.cs
- TreeBuilder.cs
- RightsManagementManager.cs
- RichTextBox.cs
- ToolStripContentPanelRenderEventArgs.cs
- GridItem.cs
- ListViewItemEventArgs.cs
- Int32KeyFrameCollection.cs
- CodeGenerationManager.cs
- EventEntry.cs
- CloudCollection.cs
- ContractSearchPattern.cs
- DocumentGridContextMenu.cs
- JsonSerializer.cs
- TextServicesCompartmentContext.cs
- PieceDirectory.cs
- EntityDataSourceChangingEventArgs.cs
- ListControl.cs
- HWStack.cs
- OverlappedContext.cs
- StrokeCollectionDefaultValueFactory.cs
- ISAPIWorkerRequest.cs
- Vector3DAnimation.cs
- X509ChainPolicy.cs
- ResourceWriter.cs
- CacheForPrimitiveTypes.cs
- DateTimeFormatInfo.cs
- ResourceLoader.cs
- WorkItem.cs
- WebPartTransformerAttribute.cs
- SoapTypeAttribute.cs
- _ReceiveMessageOverlappedAsyncResult.cs
- LinqToSqlWrapper.cs