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
- XmlLanguage.cs
- XmlRawWriterWrapper.cs
- GlyphingCache.cs
- SQLByte.cs
- KeyValueSerializer.cs
- TypeRestriction.cs
- UnsafeNativeMethods.cs
- Vector3dCollection.cs
- HtmlInputFile.cs
- ContainerUIElement3D.cs
- TableAutomationPeer.cs
- CustomErrorsSection.cs
- ItemContainerPattern.cs
- _NetworkingPerfCounters.cs
- ExtractorMetadata.cs
- WindowsListViewScroll.cs
- TypeInitializationException.cs
- Base64Decoder.cs
- UpdateEventArgs.cs
- KeyBinding.cs
- ParallelTimeline.cs
- JavaScriptSerializer.cs
- HttpCookiesSection.cs
- GZipStream.cs
- MergablePropertyAttribute.cs
- FormsAuthenticationTicket.cs
- ControlCodeDomSerializer.cs
- BooleanFunctions.cs
- DictionaryEntry.cs
- BasicHttpSecurity.cs
- AvTrace.cs
- IndexedSelectQueryOperator.cs
- EntityWrapper.cs
- GlyphRunDrawing.cs
- PreProcessInputEventArgs.cs
- Expander.cs
- CommonServiceBehaviorElement.cs
- CommonGetThemePartSize.cs
- SchemaAttDef.cs
- AvTraceDetails.cs
- DurableInstanceContextProvider.cs
- UxThemeWrapper.cs
- ColumnHeader.cs
- CroppedBitmap.cs
- ServicePoint.cs
- SocketException.cs
- Location.cs
- Internal.cs
- ListBox.cs
- WriterOutput.cs
- XmlILStorageConverter.cs
- DataGridColumnHeaderAutomationPeer.cs
- PeerCollaborationPermission.cs
- XmlDesigner.cs
- BitmapSource.cs
- AsyncPostBackErrorEventArgs.cs
- ControlBuilderAttribute.cs
- ExpressionBinding.cs
- ObjectStateEntryDbUpdatableDataRecord.cs
- PackageDigitalSignature.cs
- GroupItem.cs
- StackOverflowException.cs
- SoapElementAttribute.cs
- XmlUrlResolver.cs
- ReferencedType.cs
- Win32KeyboardDevice.cs
- StrokeDescriptor.cs
- NetTcpSecurity.cs
- WebPartCancelEventArgs.cs
- DataTable.cs
- BindingWorker.cs
- NotImplementedException.cs
- WebPartAuthorizationEventArgs.cs
- XmlILIndex.cs
- _SecureChannel.cs
- SrgsElement.cs
- XMLDiffLoader.cs
- BindableTemplateBuilder.cs
- WrappedIUnknown.cs
- MachineKeyConverter.cs
- XslNumber.cs
- wgx_exports.cs
- SocketException.cs
- TextBoxBase.cs
- BidOverLoads.cs
- ListItemCollection.cs
- MethodExpression.cs
- DeploymentSection.cs
- Deserializer.cs
- ObjectDataSourceMethodEditor.cs
- BitStream.cs
- InternalControlCollection.cs
- CancellationHandlerDesigner.cs
- HttpResponseHeader.cs
- ErrorWebPart.cs
- AsynchronousChannel.cs
- TypeLibConverter.cs
- ExpressionBinding.cs
- NamespaceList.cs
- SerializationFieldInfo.cs