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
- DrawingState.cs
- InfoCardXmlSerializer.cs
- MatrixTransform3D.cs
- CryptoKeySecurity.cs
- ListViewDataItem.cs
- GlyphsSerializer.cs
- GridItemProviderWrapper.cs
- HttpHandlersSection.cs
- UriParserTemplates.cs
- GB18030Encoding.cs
- CompositeFontInfo.cs
- DataErrorValidationRule.cs
- DictionaryManager.cs
- FilteredDataSetHelper.cs
- PointF.cs
- PageDeviceFont.cs
- SessionState.cs
- PropertyStore.cs
- TemplateContentLoader.cs
- FormClosingEvent.cs
- SqlCacheDependency.cs
- WebPartHeaderCloseVerb.cs
- ReturnEventArgs.cs
- AssemblyBuilder.cs
- DataGridViewRowCancelEventArgs.cs
- ByteStack.cs
- FunctionUpdateCommand.cs
- CodeGroup.cs
- State.cs
- GeometryDrawing.cs
- DataControlFieldCollection.cs
- XmlElementCollection.cs
- MdiWindowListStrip.cs
- OleDbDataAdapter.cs
- BaseTemplateCodeDomTreeGenerator.cs
- SqlMetaData.cs
- X509CertificateChain.cs
- TextTreeObjectNode.cs
- StateRuntime.cs
- TypedElement.cs
- DataControlFieldHeaderCell.cs
- AgileSafeNativeMemoryHandle.cs
- ConfigsHelper.cs
- HMACMD5.cs
- MimeXmlImporter.cs
- PropertyGridEditorPart.cs
- KeyboardEventArgs.cs
- SoapInteropTypes.cs
- StringPropertyBuilder.cs
- XmlHierarchicalEnumerable.cs
- XmlSchemaSimpleContentRestriction.cs
- TrackingConditionCollection.cs
- XmlFormatWriterGenerator.cs
- InvokeGenerator.cs
- SetterBase.cs
- CharEntityEncoderFallback.cs
- XmlException.cs
- TypeResolvingOptionsAttribute.cs
- SmtpAuthenticationManager.cs
- BreakRecordTable.cs
- WizardPanel.cs
- StyleSelector.cs
- MetabaseServerConfig.cs
- ObjectDataSourceMethodEditor.cs
- XPathChildIterator.cs
- GridViewDesigner.cs
- ContactManager.cs
- CacheManager.cs
- XmlAttribute.cs
- RayHitTestParameters.cs
- WebZone.cs
- ButtonAutomationPeer.cs
- DataServiceProviderWrapper.cs
- ParallelLoopState.cs
- ListViewItem.cs
- IApplicationTrustManager.cs
- BufferBuilder.cs
- SqlRecordBuffer.cs
- MessageProtectionOrder.cs
- XPathAncestorQuery.cs
- SourceSwitch.cs
- DataBoundLiteralControl.cs
- CodeCommentStatement.cs
- OdbcCommand.cs
- DocumentPageViewAutomationPeer.cs
- SuppressIldasmAttribute.cs
- XmlDocumentFragment.cs
- BackStopAuthenticationModule.cs
- ServiceHostingEnvironment.cs
- SessionStateUtil.cs
- OdbcCommandBuilder.cs
- SecurityKeyIdentifierClause.cs
- DesignColumn.cs
- ActiveXContainer.cs
- ApplicationGesture.cs
- Point3DAnimationUsingKeyFrames.cs
- RadioButtonList.cs
- SvcMapFileLoader.cs
- ScriptServiceAttribute.cs
- ITreeGenerator.cs