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
- ListSourceHelper.cs
- ImageSource.cs
- SafeFindHandle.cs
- _DigestClient.cs
- WebBrowserNavigatingEventHandler.cs
- TimeSpanMinutesConverter.cs
- CodeDirectionExpression.cs
- XmlSiteMapProvider.cs
- PointHitTestParameters.cs
- _ListenerAsyncResult.cs
- rsa.cs
- LocalBuilder.cs
- ScrollEventArgs.cs
- HelpInfo.cs
- FormsAuthenticationTicket.cs
- DefaultAutoFieldGenerator.cs
- FlatButtonAppearance.cs
- Size.cs
- RelationshipConverter.cs
- XmlEncodedRawTextWriter.cs
- SslStream.cs
- ListComponentEditor.cs
- LinqDataSourceInsertEventArgs.cs
- FaultCallbackWrapper.cs
- PeerApplicationLaunchInfo.cs
- XmlByteStreamReader.cs
- List.cs
- PeerOutputChannel.cs
- TypedElement.cs
- WebHttpBindingElement.cs
- EnvelopedSignatureTransform.cs
- Crc32.cs
- ResourceReader.cs
- AdCreatedEventArgs.cs
- SelectedGridItemChangedEvent.cs
- ProviderIncompatibleException.cs
- ItemCheckedEvent.cs
- SystemIPGlobalProperties.cs
- Mappings.cs
- FreeIndexList.cs
- ContextMenuService.cs
- CookieProtection.cs
- MimeFormImporter.cs
- ContentPosition.cs
- FileUtil.cs
- ServiceOperationInfoTypeConverter.cs
- SafeHandle.cs
- ECDiffieHellmanCngPublicKey.cs
- MetadataCollection.cs
- DataRelationPropertyDescriptor.cs
- QueryPageSettingsEventArgs.cs
- BufferModesCollection.cs
- AnnotationResourceCollection.cs
- OutputCacheProfile.cs
- DBSchemaTable.cs
- SqlCacheDependencySection.cs
- DataViewSetting.cs
- AsymmetricSecurityProtocol.cs
- NumberEdit.cs
- SqlRemoveConstantOrderBy.cs
- ListSortDescription.cs
- ApplicationId.cs
- OutputCacheSettings.cs
- InplaceBitmapMetadataWriter.cs
- FtpWebRequest.cs
- CompModSwitches.cs
- EtwTrackingBehavior.cs
- HttpHandlerAction.cs
- DataGridViewCellContextMenuStripNeededEventArgs.cs
- Vector3DCollection.cs
- Error.cs
- Mappings.cs
- FindRequestContext.cs
- LicFileLicenseProvider.cs
- GotoExpression.cs
- TypeGeneratedEventArgs.cs
- PointAnimationUsingKeyFrames.cs
- XmlSchemaSimpleTypeRestriction.cs
- StateBag.cs
- CharEntityEncoderFallback.cs
- StateBag.cs
- ProxyElement.cs
- ItemContainerGenerator.cs
- HMACSHA256.cs
- ConfigXmlDocument.cs
- TreeViewItem.cs
- XmlDownloadManager.cs
- DataContractSerializerElement.cs
- AnnotationStore.cs
- DataGridViewControlCollection.cs
- SizeChangedEventArgs.cs
- SQLBinaryStorage.cs
- SchemaAttDef.cs
- WebPartMovingEventArgs.cs
- TransactionException.cs
- HandlerFactoryWrapper.cs
- ManualResetEvent.cs
- DurableTimerExtension.cs
- StorageComplexPropertyMapping.cs
- Internal.cs