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
- SmiEventStream.cs
- ExpressionBuilderContext.cs
- DesignerVerb.cs
- InlineCollection.cs
- Geometry3D.cs
- FormatSettings.cs
- SafeProcessHandle.cs
- PerformanceCounter.cs
- Visual3D.cs
- ArgumentsParser.cs
- VisualBrush.cs
- Int32KeyFrameCollection.cs
- InputMethodStateTypeInfo.cs
- BitmapEffect.cs
- DataSourceCache.cs
- NotFiniteNumberException.cs
- Line.cs
- GridViewSelectEventArgs.cs
- ScopedMessagePartSpecification.cs
- EncoderParameters.cs
- KeySplineConverter.cs
- DataControlLinkButton.cs
- XmlNodeChangedEventArgs.cs
- OutputWindow.cs
- EdmItemCollection.cs
- HtmlEncodedRawTextWriter.cs
- RichTextBox.cs
- XmlNodeReader.cs
- VirtualPath.cs
- RegexGroup.cs
- FilterQuery.cs
- SmiRequestExecutor.cs
- OdbcUtils.cs
- SafeNativeMethods.cs
- CharacterMetrics.cs
- DataGridViewColumnConverter.cs
- EpmSourcePathSegment.cs
- MethodBody.cs
- Array.cs
- ClientSession.cs
- SQLSingle.cs
- ResXBuildProvider.cs
- ViewCellSlot.cs
- MappedMetaModel.cs
- ErrorWebPart.cs
- TextHintingModeValidation.cs
- XamlPoint3DCollectionSerializer.cs
- SamlAdvice.cs
- UIPermission.cs
- FilteredXmlReader.cs
- TableProviderWrapper.cs
- DivideByZeroException.cs
- XmlException.cs
- TabItem.cs
- ZipIOFileItemStream.cs
- RegistrationContext.cs
- TileBrush.cs
- CookielessData.cs
- KnownBoxes.cs
- ActivityDesignerLayoutSerializers.cs
- MarkupWriter.cs
- XPathEmptyIterator.cs
- ProcessThread.cs
- CodeCatchClause.cs
- DropDownList.cs
- XmlReflectionMember.cs
- MultiSelectRootGridEntry.cs
- RichTextBoxConstants.cs
- ItemDragEvent.cs
- UnsignedPublishLicense.cs
- ContentOperations.cs
- StorageEntityContainerMapping.cs
- GeneralTransform3DGroup.cs
- SoapSchemaMember.cs
- VersionedStream.cs
- MimeTypePropertyAttribute.cs
- ParameterBuilder.cs
- DesignerTransactionCloseEvent.cs
- StatusBar.cs
- ToolStripItem.cs
- BaseInfoTable.cs
- SmtpMail.cs
- LayoutTableCell.cs
- PipelineModuleStepContainer.cs
- StringValueConverter.cs
- TextTreeExtractElementUndoUnit.cs
- GenericRootAutomationPeer.cs
- XmlSchemaElement.cs
- DataBoundLiteralControl.cs
- SQLBytesStorage.cs
- PtsCache.cs
- MediaContextNotificationWindow.cs
- PolyLineSegment.cs
- PanelStyle.cs
- CaseKeyBox.ViewModel.cs
- InternalConfigHost.cs
- DerivedKeySecurityToken.cs
- Comparer.cs
- XamlFilter.cs
- DefaultValidator.cs