Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / 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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- FormViewInsertedEventArgs.cs
- FaultHandlingFilter.cs
- HttpListenerResponse.cs
- Peer.cs
- ToolBarButtonClickEvent.cs
- WinEventQueueItem.cs
- UnsafeNativeMethods.cs
- XPathSelfQuery.cs
- XmlAnyAttributeAttribute.cs
- ClientRequest.cs
- DBDataPermission.cs
- NotSupportedException.cs
- Compiler.cs
- CatalogZoneAutoFormat.cs
- ConnectionsZone.cs
- DataGridViewRowCollection.cs
- GenericWebPart.cs
- Oid.cs
- DataGridCellItemAutomationPeer.cs
- FileDialogCustomPlacesCollection.cs
- ReadOnlyAttribute.cs
- PrintingPermission.cs
- Assert.cs
- CalendarDateChangedEventArgs.cs
- GeneralTransform3D.cs
- EnvironmentPermission.cs
- SolidBrush.cs
- Encoder.cs
- EnumValidator.cs
- ImageAttributes.cs
- XamlVector3DCollectionSerializer.cs
- PopOutPanel.cs
- TaiwanLunisolarCalendar.cs
- TypeConverterAttribute.cs
- Frame.cs
- Viewport2DVisual3D.cs
- Utils.cs
- HttpRawResponse.cs
- Int32EqualityComparer.cs
- ProviderConnectionPointCollection.cs
- MatrixValueSerializer.cs
- ConfigurationManagerHelperFactory.cs
- StateChangeEvent.cs
- FixedBufferAttribute.cs
- SqlClientMetaDataCollectionNames.cs
- KeyEvent.cs
- Bitmap.cs
- JsonGlobals.cs
- Timeline.cs
- ScriptControlDescriptor.cs
- XmlNotation.cs
- CurrencyWrapper.cs
- DataSourceView.cs
- SqlTypesSchemaImporter.cs
- Camera.cs
- UTF32Encoding.cs
- DaylightTime.cs
- SafeEventLogWriteHandle.cs
- ZipPackagePart.cs
- ExeContext.cs
- RootProfilePropertySettingsCollection.cs
- NavigationWindowAutomationPeer.cs
- ClientApiGenerator.cs
- RadialGradientBrush.cs
- CompositeDataBoundControl.cs
- Style.cs
- VisualTarget.cs
- FakeModelItemImpl.cs
- ViewStateModeByIdAttribute.cs
- TextSearch.cs
- TypographyProperties.cs
- TableLayout.cs
- InternalDuplexChannelListener.cs
- XmlAtomicValue.cs
- IndexExpression.cs
- StaticTextPointer.cs
- TranslateTransform3D.cs
- SiteMapNodeItem.cs
- DataServiceEntityAttribute.cs
- ValidatorCompatibilityHelper.cs
- TemplateControlCodeDomTreeGenerator.cs
- NotSupportedException.cs
- HandlerBase.cs
- HttpSessionStateBase.cs
- ProfilePropertySettingsCollection.cs
- ZipIOCentralDirectoryDigitalSignature.cs
- WindowProviderWrapper.cs
- clipboard.cs
- LocalFileSettingsProvider.cs
- DataServiceProviderMethods.cs
- MetadataCache.cs
- ContainerSelectorActiveEvent.cs
- HtmlTableRow.cs
- assertwrapper.cs
- CollectionBase.cs
- validationstate.cs
- AccessControlList.cs
- TypeExtension.cs
- ApplicationDirectory.cs
- ReadWriteSpinLock.cs