Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / Data / System / Data / SqlClient / SqlConnectionPoolGroupProviderInfo.cs / 1 / 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
- InternalTypeHelper.cs
- Annotation.cs
- DebuggerAttributes.cs
- MTConfigUtil.cs
- Int32Rect.cs
- EditableLabelControl.cs
- InsufficientMemoryException.cs
- EdmConstants.cs
- ThrowHelper.cs
- BatchParser.cs
- GeneralTransform3D.cs
- SByte.cs
- SettingsSection.cs
- FilterableAttribute.cs
- RegexCode.cs
- PtsHelper.cs
- OdbcCommand.cs
- ThreadInterruptedException.cs
- TableCellCollection.cs
- Block.cs
- TextChangedEventArgs.cs
- SkinBuilder.cs
- SqlEnums.cs
- EntityTypeEmitter.cs
- ThreadStartException.cs
- XhtmlBasicCalendarAdapter.cs
- IntSumAggregationOperator.cs
- EntityDataSourceEntitySetNameItem.cs
- UrlAuthorizationModule.cs
- ConfigXmlComment.cs
- StrongNameMembershipCondition.cs
- InstallerTypeAttribute.cs
- TrackingQueryElement.cs
- SspiHelper.cs
- HideDisabledControlAdapter.cs
- BitmapEffectInputData.cs
- LoadRetryConstantStrategy.cs
- MinMaxParagraphWidth.cs
- ToolStripSystemRenderer.cs
- COAUTHINFO.cs
- ScrollItemProviderWrapper.cs
- IncomingWebResponseContext.cs
- Executor.cs
- CngKey.cs
- XmlSchemaSet.cs
- DataGridViewElement.cs
- CultureTable.cs
- SafeBitVector32.cs
- TypedTableBase.cs
- TextSelectionHighlightLayer.cs
- BitmapEffect.cs
- SerializerDescriptor.cs
- XmlUrlResolver.cs
- DesignerAutoFormatCollection.cs
- HttpHandlerAction.cs
- CommandLibraryHelper.cs
- Variant.cs
- BitmapEffectDrawingContextState.cs
- DesignerTransaction.cs
- Number.cs
- sitestring.cs
- SerializationStore.cs
- CodeSubDirectoriesCollection.cs
- Substitution.cs
- PropertyEmitterBase.cs
- ConfigurationManagerHelperFactory.cs
- ListItem.cs
- EmptyElement.cs
- WebPartCancelEventArgs.cs
- TypeBuilder.cs
- RangeValuePatternIdentifiers.cs
- AssemblyAttributes.cs
- SqlFunctionAttribute.cs
- Expression.cs
- StringSource.cs
- EffectiveValueEntry.cs
- ParserOptions.cs
- EncryptionUtility.cs
- CurrentTimeZone.cs
- ClientSponsor.cs
- LastQueryOperator.cs
- ScrollableControl.cs
- DynamicPropertyReader.cs
- FormViewCommandEventArgs.cs
- SystemIcmpV6Statistics.cs
- DynamicField.cs
- SqlCommand.cs
- COM2ComponentEditor.cs
- PathParser.cs
- Oid.cs
- DbConnectionPoolOptions.cs
- TextOnlyOutput.cs
- WindowsSolidBrush.cs
- NameValueCollection.cs
- RowParagraph.cs
- GACIdentityPermission.cs
- MissingManifestResourceException.cs
- XmlSiteMapProvider.cs
- ProfilePropertySettingsCollection.cs
- CollectionViewGroupRoot.cs