Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Data / System / Data / SqlClient / SqlConnectionPoolGroupProviderInfo.cs / 1305376 / SqlConnectionPoolGroupProviderInfo.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //[....] //----------------------------------------------------------------------------- namespace System.Data.SqlClient { using System; using System.Data; using System.Data.Common; using System.Data.ProviderBase; sealed internal class SqlConnectionPoolGroupProviderInfo : DbConnectionPoolGroupProviderInfo { private string _alias; private System.Security.PermissionSet _failoverPermissionSet; private string _failoverPartner; private bool _useFailoverPartner; internal SqlConnectionPoolGroupProviderInfo(SqlConnectionString connectionOptions) { // This is for the case where the user specified the failover partner // in the connection string and we have not yet connected to get the // env change. _failoverPartner = connectionOptions.FailoverPartner; if (ADP.IsEmpty(_failoverPartner)) { _failoverPartner = null; } } internal string FailoverPartner { get { return _failoverPartner; } } internal bool UseFailoverPartner { get { return _useFailoverPartner; } } internal void AliasCheck(string server) { if (_alias != server) { lock(this) { if (null == _alias) { _alias = server; } else if (_alias != server) { Bid.Trace("alias change detected. Clearing PoolGroup\n"); base.PoolGroup.Clear(); _alias = server; } } } } private System.Security.PermissionSet CreateFailoverPermission(SqlConnectionString userConnectionOptions, string actualFailoverPartner) { string keywordToReplace; // RULES FOR CONSTRUCTING THE CONNECTION STRING TO DEMAND ON: // // 1) If no Failover Partner was specified in the original string: // // Server=actualFailoverPartner // // 2) If Failover Partner was specified in the original string: // // Server=originalValue; Failover Partner=actualFailoverPartner // // NOTE: in all cases, when we get a failover partner name from // the server, we will use that name over what was specified // in the original connection string. if (null == userConnectionOptions[SqlConnectionString.KEY.FailoverPartner]) { keywordToReplace = SqlConnectionString.KEY.Data_Source; } else { keywordToReplace = SqlConnectionString.KEY.FailoverPartner; } string failoverConnectionString = userConnectionOptions.ExpandKeyword(keywordToReplace, actualFailoverPartner); return (new SqlConnectionString(failoverConnectionString)).CreatePermissionSet(); } internal void FailoverCheck(SqlInternalConnection connection, bool actualUseFailoverPartner, SqlConnectionString userConnectionOptions, string actualFailoverPartner) { if (UseFailoverPartner != actualUseFailoverPartner) { // Bid.Trace(" Failover detected. failover partner='%ls'. Clearing PoolGroup\n", actualFailoverPartner); base.PoolGroup.Clear(); _useFailoverPartner = actualUseFailoverPartner; } // Only construct a new permission set when we're connecting to the // primary data source, not the failover partner. if (!_useFailoverPartner && _failoverPartner != actualFailoverPartner) { // NOTE: we optimisitically generate the permission set to keep // lock short, but we only do this when we get a new // failover partner. // System.Security.PermissionSet failoverPermissionSet = CreateFailoverPermission(userConnectionOptions, actualFailoverPartner); lock (this) { if (_failoverPartner != actualFailoverPartner) { _failoverPartner = actualFailoverPartner; _failoverPermissionSet = failoverPermissionSet; } } } } internal void FailoverPermissionDemand() { if (_useFailoverPartner) { // Note that we only demand when there is a permission set, which only // happens once we've identified a failover situation in FailoverCheck System.Security.PermissionSet failoverPermissionSet = _failoverPermissionSet; if (null != failoverPermissionSet) { // demand on pooled failover connections failoverPermissionSet.Demand(); } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //[....] //----------------------------------------------------------------------------- namespace System.Data.SqlClient { using System; using System.Data; using System.Data.Common; using System.Data.ProviderBase; sealed internal class SqlConnectionPoolGroupProviderInfo : DbConnectionPoolGroupProviderInfo { private string _alias; private System.Security.PermissionSet _failoverPermissionSet; private string _failoverPartner; private bool _useFailoverPartner; internal SqlConnectionPoolGroupProviderInfo(SqlConnectionString connectionOptions) { // This is for the case where the user specified the failover partner // in the connection string and we have not yet connected to get the // env change. _failoverPartner = connectionOptions.FailoverPartner; if (ADP.IsEmpty(_failoverPartner)) { _failoverPartner = null; } } internal string FailoverPartner { get { return _failoverPartner; } } internal bool UseFailoverPartner { get { return _useFailoverPartner; } } internal void AliasCheck(string server) { if (_alias != server) { lock(this) { if (null == _alias) { _alias = server; } else if (_alias != server) { Bid.Trace("alias change detected. Clearing PoolGroup\n"); base.PoolGroup.Clear(); _alias = server; } } } } private System.Security.PermissionSet CreateFailoverPermission(SqlConnectionString userConnectionOptions, string actualFailoverPartner) { string keywordToReplace; // RULES FOR CONSTRUCTING THE CONNECTION STRING TO DEMAND ON: // // 1) If no Failover Partner was specified in the original string: // // Server=actualFailoverPartner // // 2) If Failover Partner was specified in the original string: // // Server=originalValue; Failover Partner=actualFailoverPartner // // NOTE: in all cases, when we get a failover partner name from // the server, we will use that name over what was specified // in the original connection string. if (null == userConnectionOptions[SqlConnectionString.KEY.FailoverPartner]) { keywordToReplace = SqlConnectionString.KEY.Data_Source; } else { keywordToReplace = SqlConnectionString.KEY.FailoverPartner; } string failoverConnectionString = userConnectionOptions.ExpandKeyword(keywordToReplace, actualFailoverPartner); return (new SqlConnectionString(failoverConnectionString)).CreatePermissionSet(); } internal void FailoverCheck(SqlInternalConnection connection, bool actualUseFailoverPartner, SqlConnectionString userConnectionOptions, string actualFailoverPartner) { if (UseFailoverPartner != actualUseFailoverPartner) { // Bid.Trace(" Failover detected. failover partner='%ls'. Clearing PoolGroup\n", actualFailoverPartner); base.PoolGroup.Clear(); _useFailoverPartner = actualUseFailoverPartner; } // Only construct a new permission set when we're connecting to the // primary data source, not the failover partner. if (!_useFailoverPartner && _failoverPartner != actualFailoverPartner) { // NOTE: we optimisitically generate the permission set to keep // lock short, but we only do this when we get a new // failover partner. // System.Security.PermissionSet failoverPermissionSet = CreateFailoverPermission(userConnectionOptions, actualFailoverPartner); lock (this) { if (_failoverPartner != actualFailoverPartner) { _failoverPartner = actualFailoverPartner; _failoverPermissionSet = failoverPermissionSet; } } } } internal void FailoverPermissionDemand() { if (_useFailoverPartner) { // Note that we only demand when there is a permission set, which only // happens once we've identified a failover situation in FailoverCheck System.Security.PermissionSet failoverPermissionSet = _failoverPermissionSet; if (null != failoverPermissionSet) { // demand on pooled failover connections failoverPermissionSet.Demand(); } } } } } // 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
- ScrollBar.cs
- DataGridViewDataErrorEventArgs.cs
- StateItem.cs
- TogglePattern.cs
- compensatingcollection.cs
- TextEditorThreadLocalStore.cs
- UserControlParser.cs
- TimeBoundedCache.cs
- ExceptionHandlersDesigner.cs
- Token.cs
- AmbientProperties.cs
- ProcessRequestArgs.cs
- PagedDataSource.cs
- IndicShape.cs
- ExternalFile.cs
- StatusBarPanel.cs
- PeerToPeerException.cs
- ZipIOCentralDirectoryDigitalSignature.cs
- GroupStyle.cs
- COM2PropertyBuilderUITypeEditor.cs
- PathNode.cs
- StructuredType.cs
- ObjectTag.cs
- GPPOINT.cs
- COM2ComponentEditor.cs
- MonthCalendar.cs
- InternalDispatchObject.cs
- TreeNodeSelectionProcessor.cs
- ObjectIDGenerator.cs
- namescope.cs
- MailMessage.cs
- CatalogZone.cs
- SynchronizedDispatch.cs
- SqlPersonalizationProvider.cs
- StdValidatorsAndConverters.cs
- AuthorizationContext.cs
- TypeBrowser.xaml.cs
- ProtocolsSection.cs
- IndexedString.cs
- Delegate.cs
- DecimalAnimationBase.cs
- GridViewUpdateEventArgs.cs
- HMACSHA1.cs
- TemplateControlCodeDomTreeGenerator.cs
- AsymmetricKeyExchangeFormatter.cs
- HtmlButton.cs
- BitmapInitialize.cs
- UTF7Encoding.cs
- ControlParameter.cs
- DataTrigger.cs
- ToolStripSeparatorRenderEventArgs.cs
- DataViewManagerListItemTypeDescriptor.cs
- AjaxFrameworkAssemblyAttribute.cs
- ItemsControl.cs
- CreateSequenceResponse.cs
- NativeMethods.cs
- XmlSignificantWhitespace.cs
- OAVariantLib.cs
- XmlDownloadManager.cs
- Int32CollectionValueSerializer.cs
- ColumnMapProcessor.cs
- ExplicitDiscriminatorMap.cs
- EmbeddedMailObjectsCollection.cs
- MultiTrigger.cs
- AppDomainUnloadedException.cs
- TypeSystem.cs
- CodeTypeMemberCollection.cs
- PersonalizationProviderCollection.cs
- TaskbarItemInfo.cs
- SolidColorBrush.cs
- FontCollection.cs
- Setter.cs
- _OSSOCK.cs
- LayoutEvent.cs
- codemethodreferenceexpression.cs
- WindowAutomationPeer.cs
- XmlLanguage.cs
- AdornerLayer.cs
- BrowserCapabilitiesCompiler.cs
- XmlDeclaration.cs
- TypeForwardedToAttribute.cs
- shaperfactory.cs
- ToolBar.cs
- AudioLevelUpdatedEventArgs.cs
- ClientProtocol.cs
- ImageButton.cs
- XmlSchemaSimpleContent.cs
- BamlWriter.cs
- CapabilitiesPattern.cs
- LabelDesigner.cs
- StringSource.cs
- ConstrainedDataObject.cs
- ModelTreeEnumerator.cs
- BehaviorEditorPart.cs
- TextElement.cs
- WebPartConnectionsCloseVerb.cs
- ObjectSelectorEditor.cs
- ColorContextHelper.cs
- DriveNotFoundException.cs
- ConfigurationManagerInternalFactory.cs