diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index 9d0d3c5fc1..d1ddbf37af 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -33,7 +33,7 @@ Microsoft\Data\SqlClient\SqlClientEventSource.cs - + Microsoft\Data\SqlClient\SqlClientLogger.cs @@ -66,7 +66,7 @@ Microsoft\Data\SqlClient\ColumnEncryptionKeyInfo.cs - + Microsoft\Data\SqlClient\OnChangedEventHandler.cs @@ -143,13 +143,17 @@ + + + + @@ -657,12 +661,12 @@ - + - + diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationProviderManager.NetCoreApp.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationProviderManager.NetCoreApp.cs new file mode 100644 index 0000000000..c02a96e236 --- /dev/null +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationProviderManager.NetCoreApp.cs @@ -0,0 +1,134 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Configuration; + +namespace Microsoft.Data.SqlClient +{ + internal partial class SqlAuthenticationProviderManager + { + private readonly SqlAuthenticationInitializer _initializer; + + static SqlAuthenticationProviderManager() + { + var activeDirectoryAuthNativeProvider = new ActiveDirectoryNativeAuthenticationProvider(); + SqlAuthenticationProviderConfigurationSection configurationSection; + + try + { + configurationSection = (SqlAuthenticationProviderConfigurationSection)ConfigurationManager.GetSection(SqlAuthenticationProviderConfigurationSection.Name); + } + catch (ConfigurationErrorsException e) + { + throw SQL.CannotGetAuthProviderConfig(e); + } + + Instance = new SqlAuthenticationProviderManager(configurationSection); + Instance.SetProvider(SqlAuthenticationMethod.ActiveDirectoryPassword, activeDirectoryAuthNativeProvider); + } + + /// + /// Constructor. + /// + public SqlAuthenticationProviderManager(SqlAuthenticationProviderConfigurationSection configSection = null) + { + var methodName = "Ctor"; + _typeName = GetType().Name; + _providers = new ConcurrentDictionary(); + var authenticationsWithAppSpecifiedProvider = new HashSet(); + _authenticationsWithAppSpecifiedProvider = authenticationsWithAppSpecifiedProvider; + + if (configSection == null) + { + _sqlAuthLogger.LogInfo(_typeName, methodName, "No SqlAuthProviders configuration section found."); + return; + } + + // Create user-defined auth initializer, if any. + if (!string.IsNullOrEmpty(configSection.InitializerType)) + { + try + { + var initializerType = Type.GetType(configSection.InitializerType, true); + _initializer = (SqlAuthenticationInitializer)Activator.CreateInstance(initializerType); + _initializer.Initialize(); + } + catch (Exception e) + { + throw SQL.CannotCreateSqlAuthInitializer(configSection.InitializerType, e); + } + _sqlAuthLogger.LogInfo(_typeName, methodName, "Created user-defined SqlAuthenticationInitializer."); + } + else + { + _sqlAuthLogger.LogInfo(_typeName, methodName, "No user-defined SqlAuthenticationInitializer found."); + } + + // add user-defined providers, if any. + if (configSection.Providers != null && configSection.Providers.Count > 0) + { + foreach (ProviderSettings providerSettings in configSection.Providers) + { + SqlAuthenticationMethod authentication = AuthenticationEnumFromString(providerSettings.Name); + SqlAuthenticationProvider provider; + try + { + var providerType = Type.GetType(providerSettings.Type, true); + provider = (SqlAuthenticationProvider)Activator.CreateInstance(providerType); + } + catch (Exception e) + { + throw SQL.CannotCreateAuthProvider(authentication.ToString(), providerSettings.Type, e); + } + if (!provider.IsSupported(authentication)) + { + throw SQL.UnsupportedAuthenticationByProvider(authentication.ToString(), providerSettings.Type); + } + + _providers[authentication] = provider; + authenticationsWithAppSpecifiedProvider.Add(authentication); + _sqlAuthLogger.LogInfo(_typeName, methodName, string.Format("Added user-defined auth provider: {0} for authentication {1}.", providerSettings?.Type, authentication)); + } + } + else + { + _sqlAuthLogger.LogInfo(_typeName, methodName, "No user-defined auth providers."); + } + } + + private static SqlAuthenticationMethod AuthenticationEnumFromString(string authentication) + { + switch (authentication.ToLowerInvariant()) + { + case ActiveDirectoryPassword: + return SqlAuthenticationMethod.ActiveDirectoryPassword; + default: + throw SQL.UnsupportedAuthentication(authentication); + } + } + + /// + /// The configuration section definition for reading app.config. + /// + internal class SqlAuthenticationProviderConfigurationSection : ConfigurationSection + { + public const string Name = "SqlAuthenticationProviders"; + + /// + /// User-defined auth providers. + /// + [ConfigurationProperty("providers")] + public ProviderSettingsCollection Providers => (ProviderSettingsCollection)base["providers"]; + + /// + /// User-defined initializer. + /// + [ConfigurationProperty("initializerType")] + public string InitializerType => base["initializerType"] as string; + } + } +} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationProviderManager.NetStandard.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationProviderManager.NetStandard.cs new file mode 100644 index 0000000000..ef6328af0d --- /dev/null +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationProviderManager.NetStandard.cs @@ -0,0 +1,16 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Microsoft.Data.SqlClient +{ + internal partial class SqlAuthenticationProviderManager + { + static SqlAuthenticationProviderManager() + { + var activeDirectoryAuthNativeProvider = new ActiveDirectoryNativeAuthenticationProvider(); + Instance = new SqlAuthenticationProviderManager(); + Instance.SetProvider(SqlAuthenticationMethod.ActiveDirectoryPassword, activeDirectoryAuthNativeProvider); + } + } +} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationProviderManager.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationProviderManager.cs index 0d382aa512..b9a002a240 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationProviderManager.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationProviderManager.cs @@ -10,106 +10,31 @@ namespace Microsoft.Data.SqlClient { - /// /// Authentication provider manager. /// - internal class SqlAuthenticationProviderManager + internal partial class SqlAuthenticationProviderManager { private const string ActiveDirectoryPassword = "active directory password"; private const string ActiveDirectoryIntegrated = "active directory integrated"; private const string ActiveDirectoryInteractive = "active directory interactive"; - static SqlAuthenticationProviderManager() - { - var activeDirectoryAuthNativeProvider = new ActiveDirectoryNativeAuthenticationProvider(); - SqlAuthenticationProviderConfigurationSection configurationSection; - try - { - configurationSection = (SqlAuthenticationProviderConfigurationSection)ConfigurationManager.GetSection(SqlAuthenticationProviderConfigurationSection.Name); - } - catch (ConfigurationErrorsException e) - { - throw SQL.CannotGetAuthProviderConfig(e); - } - Instance = new SqlAuthenticationProviderManager(configurationSection); - Instance.SetProvider(SqlAuthenticationMethod.ActiveDirectoryPassword, activeDirectoryAuthNativeProvider); - } - public static readonly SqlAuthenticationProviderManager Instance; - private readonly string _typeName; - private readonly SqlAuthenticationInitializer _initializer; private readonly IReadOnlyCollection _authenticationsWithAppSpecifiedProvider; private readonly ConcurrentDictionary _providers; private readonly SqlClientLogger _sqlAuthLogger = new SqlClientLogger(); + public static readonly SqlAuthenticationProviderManager Instance; + /// /// Constructor. /// - public SqlAuthenticationProviderManager(SqlAuthenticationProviderConfigurationSection configSection) + public SqlAuthenticationProviderManager() { _typeName = GetType().Name; - var methodName = "Ctor"; _providers = new ConcurrentDictionary(); - var authenticationsWithAppSpecifiedProvider = new HashSet(); - _authenticationsWithAppSpecifiedProvider = authenticationsWithAppSpecifiedProvider; - - if (configSection == null) - { - _sqlAuthLogger.LogInfo(_typeName, methodName, "No SqlAuthProviders configuration section found."); - return; - } - - // Create user-defined auth initializer, if any. - // - if (!string.IsNullOrEmpty(configSection.InitializerType)) - { - try - { - var initializerType = Type.GetType(configSection.InitializerType, true); - _initializer = (SqlAuthenticationInitializer)Activator.CreateInstance(initializerType); - _initializer.Initialize(); - } - catch (Exception e) - { - throw SQL.CannotCreateSqlAuthInitializer(configSection.InitializerType, e); - } - _sqlAuthLogger.LogInfo(_typeName, methodName, "Created user-defined SqlAuthenticationInitializer."); - } - else - { - _sqlAuthLogger.LogInfo(_typeName, methodName, "No user-defined SqlAuthenticationInitializer found."); - } - - // add user-defined providers, if any. - // - if (configSection.Providers != null && configSection.Providers.Count > 0) - { - foreach (ProviderSettings providerSettings in configSection.Providers) - { - SqlAuthenticationMethod authentication = AuthenticationEnumFromString(providerSettings.Name); - SqlAuthenticationProvider provider; - try - { - var providerType = Type.GetType(providerSettings.Type, true); - provider = (SqlAuthenticationProvider)Activator.CreateInstance(providerType); - } - catch (Exception e) - { - throw SQL.CannotCreateAuthProvider(authentication.ToString(), providerSettings.Type, e); - } - if (!provider.IsSupported(authentication)) - throw SQL.UnsupportedAuthenticationByProvider(authentication.ToString(), providerSettings.Type); - - _providers[authentication] = provider; - authenticationsWithAppSpecifiedProvider.Add(authentication); - _sqlAuthLogger.LogInfo(_typeName, methodName, string.Format("Added user-defined auth provider: {0} for authentication {1}.", providerSettings?.Type, authentication)); - } - } - else - { - _sqlAuthLogger.LogInfo(_typeName, methodName, "No user-defined auth providers."); - } + _authenticationsWithAppSpecifiedProvider = new HashSet(); + _sqlAuthLogger.LogInfo(_typeName, "Ctor", "No SqlAuthProviders configuration section found."); } /// @@ -156,17 +81,6 @@ public bool SetProvider(SqlAuthenticationMethod authenticationMethod, SqlAuthent return true; } - private static SqlAuthenticationMethod AuthenticationEnumFromString(string authentication) - { - switch (authentication.ToLowerInvariant()) - { - case ActiveDirectoryPassword: - return SqlAuthenticationMethod.ActiveDirectoryPassword; - default: - throw SQL.UnsupportedAuthentication(authentication); - } - } - private static string GetProviderType(SqlAuthenticationProvider provider) { if (provider == null) @@ -175,26 +89,6 @@ private static string GetProviderType(SqlAuthenticationProvider provider) } } - /// - /// The configuration section definition for reading app.config. - /// - internal class SqlAuthenticationProviderConfigurationSection : ConfigurationSection - { - public const string Name = "SqlAuthenticationProviders"; - - /// - /// User-defined auth providers. - /// - [ConfigurationProperty("providers")] - public ProviderSettingsCollection Providers => (ProviderSettingsCollection)base["providers"]; - - /// - /// User-defined initializer. - /// - [ConfigurationProperty("initializerType")] - public string InitializerType => base["initializerType"] as string; - } - /// public abstract class SqlAuthenticationInitializer { diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientDiagnosticListenerExtensions.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientDiagnosticListenerExtensions.cs index d8b8b073c3..7bcd7cffb5 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientDiagnosticListenerExtensions.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientDiagnosticListenerExtensions.cs @@ -38,7 +38,7 @@ internal static class SqlClientDiagnosticListenerExtensions public const string SqlAfterRollbackTransaction = SqlClientPrefix + nameof(WriteTransactionRollbackAfter); public const string SqlErrorRollbackTransaction = SqlClientPrefix + nameof(WriteTransactionRollbackError); - public static Guid WriteCommandBefore(this DiagnosticListener @this, SqlCommand sqlCommand, SqlTransaction transaction, [CallerMemberName] string operation = "") + public static Guid WriteCommandBefore(this SqlDiagnosticListener @this, SqlCommand sqlCommand, SqlTransaction transaction, [CallerMemberName] string operation = "") { if (@this.IsEnabled(SqlBeforeExecuteCommand)) { @@ -62,7 +62,7 @@ public static Guid WriteCommandBefore(this DiagnosticListener @this, SqlCommand return Guid.Empty; } - public static void WriteCommandAfter(this DiagnosticListener @this, Guid operationId, SqlCommand sqlCommand, SqlTransaction transaction, [CallerMemberName] string operation = "") + public static void WriteCommandAfter(this SqlDiagnosticListener @this, Guid operationId, SqlCommand sqlCommand, SqlTransaction transaction, [CallerMemberName] string operation = "") { if (@this.IsEnabled(SqlAfterExecuteCommand)) { @@ -81,7 +81,7 @@ public static void WriteCommandAfter(this DiagnosticListener @this, Guid operati } } - public static void WriteCommandError(this DiagnosticListener @this, Guid operationId, SqlCommand sqlCommand, SqlTransaction transaction, Exception ex, [CallerMemberName] string operation = "") + public static void WriteCommandError(this SqlDiagnosticListener @this, Guid operationId, SqlCommand sqlCommand, SqlTransaction transaction, Exception ex, [CallerMemberName] string operation = "") { if (@this.IsEnabled(SqlErrorExecuteCommand)) { @@ -100,7 +100,7 @@ public static void WriteCommandError(this DiagnosticListener @this, Guid operati } } - public static Guid WriteConnectionOpenBefore(this DiagnosticListener @this, SqlConnection sqlConnection, [CallerMemberName] string operation = "") + public static Guid WriteConnectionOpenBefore(this SqlDiagnosticListener @this, SqlConnection sqlConnection, [CallerMemberName] string operation = "") { if (@this.IsEnabled(SqlBeforeOpenConnection)) { @@ -123,7 +123,7 @@ public static Guid WriteConnectionOpenBefore(this DiagnosticListener @this, SqlC return Guid.Empty; } - public static void WriteConnectionOpenAfter(this DiagnosticListener @this, Guid operationId, SqlConnection sqlConnection, [CallerMemberName] string operation = "") + public static void WriteConnectionOpenAfter(this SqlDiagnosticListener @this, Guid operationId, SqlConnection sqlConnection, [CallerMemberName] string operation = "") { if (@this.IsEnabled(SqlAfterOpenConnection)) { @@ -142,7 +142,7 @@ public static void WriteConnectionOpenAfter(this DiagnosticListener @this, Guid } } - public static void WriteConnectionOpenError(this DiagnosticListener @this, Guid operationId, SqlConnection sqlConnection, Exception ex, [CallerMemberName] string operation = "") + public static void WriteConnectionOpenError(this SqlDiagnosticListener @this, Guid operationId, SqlConnection sqlConnection, Exception ex, [CallerMemberName] string operation = "") { if (@this.IsEnabled(SqlErrorOpenConnection)) { @@ -161,7 +161,7 @@ public static void WriteConnectionOpenError(this DiagnosticListener @this, Guid } } - public static Guid WriteConnectionCloseBefore(this DiagnosticListener @this, SqlConnection sqlConnection, [CallerMemberName] string operation = "") + public static Guid WriteConnectionCloseBefore(this SqlDiagnosticListener @this, SqlConnection sqlConnection, [CallerMemberName] string operation = "") { if (@this.IsEnabled(SqlBeforeCloseConnection)) { @@ -185,7 +185,7 @@ public static Guid WriteConnectionCloseBefore(this DiagnosticListener @this, Sql return Guid.Empty; } - public static void WriteConnectionCloseAfter(this DiagnosticListener @this, Guid operationId, Guid clientConnectionId, SqlConnection sqlConnection, [CallerMemberName] string operation = "") + public static void WriteConnectionCloseAfter(this SqlDiagnosticListener @this, Guid operationId, Guid clientConnectionId, SqlConnection sqlConnection, [CallerMemberName] string operation = "") { if (@this.IsEnabled(SqlAfterCloseConnection)) { @@ -203,7 +203,7 @@ public static void WriteConnectionCloseAfter(this DiagnosticListener @this, Guid } } - public static void WriteConnectionCloseError(this DiagnosticListener @this, Guid operationId, Guid clientConnectionId, SqlConnection sqlConnection, Exception ex, [CallerMemberName] string operation = "") + public static void WriteConnectionCloseError(this SqlDiagnosticListener @this, Guid operationId, Guid clientConnectionId, SqlConnection sqlConnection, Exception ex, [CallerMemberName] string operation = "") { if (@this.IsEnabled(SqlErrorCloseConnection)) { @@ -222,7 +222,7 @@ public static void WriteConnectionCloseError(this DiagnosticListener @this, Guid } } - public static Guid WriteTransactionCommitBefore(this DiagnosticListener @this, IsolationLevel isolationLevel, SqlConnection connection, SqlInternalTransaction transaction, [CallerMemberName] string operation = "") + public static Guid WriteTransactionCommitBefore(this SqlDiagnosticListener @this, IsolationLevel isolationLevel, SqlConnection connection, SqlInternalTransaction transaction, [CallerMemberName] string operation = "") { if (@this.IsEnabled(SqlBeforeCommitTransaction)) { @@ -246,7 +246,7 @@ public static Guid WriteTransactionCommitBefore(this DiagnosticListener @this, I return Guid.Empty; } - public static void WriteTransactionCommitAfter(this DiagnosticListener @this, Guid operationId, IsolationLevel isolationLevel, SqlConnection connection, SqlInternalTransaction transaction, [CallerMemberName] string operation = "") + public static void WriteTransactionCommitAfter(this SqlDiagnosticListener @this, Guid operationId, IsolationLevel isolationLevel, SqlConnection connection, SqlInternalTransaction transaction, [CallerMemberName] string operation = "") { if (@this.IsEnabled(SqlAfterCommitTransaction)) { @@ -264,7 +264,7 @@ public static void WriteTransactionCommitAfter(this DiagnosticListener @this, Gu } } - public static void WriteTransactionCommitError(this DiagnosticListener @this, Guid operationId, IsolationLevel isolationLevel, SqlConnection connection, SqlInternalTransaction transaction, Exception ex, [CallerMemberName] string operation = "") + public static void WriteTransactionCommitError(this SqlDiagnosticListener @this, Guid operationId, IsolationLevel isolationLevel, SqlConnection connection, SqlInternalTransaction transaction, Exception ex, [CallerMemberName] string operation = "") { if (@this.IsEnabled(SqlErrorCommitTransaction)) { @@ -283,7 +283,7 @@ public static void WriteTransactionCommitError(this DiagnosticListener @this, Gu } } - public static Guid WriteTransactionRollbackBefore(this DiagnosticListener @this, IsolationLevel isolationLevel, SqlConnection connection, SqlInternalTransaction transaction, string transactionName = null, [CallerMemberName] string operation = "") + public static Guid WriteTransactionRollbackBefore(this SqlDiagnosticListener @this, IsolationLevel isolationLevel, SqlConnection connection, SqlInternalTransaction transaction, string transactionName = null, [CallerMemberName] string operation = "") { if (@this.IsEnabled(SqlBeforeRollbackTransaction)) { @@ -308,7 +308,7 @@ public static Guid WriteTransactionRollbackBefore(this DiagnosticListener @this, return Guid.Empty; } - public static void WriteTransactionRollbackAfter(this DiagnosticListener @this, Guid operationId, IsolationLevel isolationLevel, SqlConnection connection, SqlInternalTransaction transaction, string transactionName = null, [CallerMemberName] string operation = "") + public static void WriteTransactionRollbackAfter(this SqlDiagnosticListener @this, Guid operationId, IsolationLevel isolationLevel, SqlConnection connection, SqlInternalTransaction transaction, string transactionName = null, [CallerMemberName] string operation = "") { if (@this.IsEnabled(SqlAfterRollbackTransaction)) { @@ -327,7 +327,7 @@ public static void WriteTransactionRollbackAfter(this DiagnosticListener @this, } } - public static void WriteTransactionRollbackError(this DiagnosticListener @this, Guid operationId, IsolationLevel isolationLevel, SqlConnection connection, SqlInternalTransaction transaction, Exception ex, string transactionName = null, [CallerMemberName] string operation = "") + public static void WriteTransactionRollbackError(this SqlDiagnosticListener @this, Guid operationId, IsolationLevel isolationLevel, SqlConnection connection, SqlInternalTransaction transaction, Exception ex, string transactionName = null, [CallerMemberName] string operation = "") { if (@this.IsEnabled(SqlErrorRollbackTransaction)) { diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs index 9f71f8a5b3..a862d74bcf 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs @@ -69,7 +69,7 @@ public sealed partial class SqlCommand : DbCommand, ICloneable private static bool _forceInternalEndQuery = false; #endif - private static readonly DiagnosticListener _diagnosticListener = new DiagnosticListener(SqlClientDiagnosticListenerExtensions.DiagnosticListenerName); + private static readonly SqlDiagnosticListener _diagnosticListener = new SqlDiagnosticListener(SqlClientDiagnosticListenerExtensions.DiagnosticListenerName); private bool _parentOperationStarted = false; internal static readonly Action s_cancelIgnoreFailure = CancelIgnoreFailureCallback; diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnection.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnection.cs index 201763a227..344702dae2 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnection.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnection.cs @@ -61,7 +61,7 @@ private enum CultureCheckState : uint private int _reconnectCount; // diagnostics listener - private static readonly DiagnosticListener s_diagnosticListener = new DiagnosticListener(SqlClientDiagnosticListenerExtensions.DiagnosticListenerName); + private static readonly SqlDiagnosticListener s_diagnosticListener = new SqlDiagnosticListener(SqlClientDiagnosticListenerExtensions.DiagnosticListenerName); // Transient Fault handling flag. This is needed to convey to the downstream mechanism of connection establishment, if Transient Fault handling should be used or not // The downstream handling of Connection open is the same for idle connection resiliency. Currently we want to apply transient fault handling only to the connections opened @@ -2065,5 +2065,3 @@ private SqlUdtInfo GetInfoFromType(Type t) } } } - - diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlDiagnosticListener.NetCoreApp.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlDiagnosticListener.NetCoreApp.cs new file mode 100644 index 0000000000..ec3b6549b3 --- /dev/null +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlDiagnosticListener.NetCoreApp.cs @@ -0,0 +1,15 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Diagnostics; + +namespace Microsoft.Data.SqlClient +{ + internal sealed class SqlDiagnosticListener : DiagnosticListener + { + public SqlDiagnosticListener(string name) : base(name) + { + } + } +} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlDiagnosticListener.NetStandard.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlDiagnosticListener.NetStandard.cs new file mode 100644 index 0000000000..726a24c934 --- /dev/null +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlDiagnosticListener.NetStandard.cs @@ -0,0 +1,36 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Generic; + +namespace Microsoft.Data.SqlClient +{ + internal sealed class SqlDiagnosticListener : IObservable> + { + public SqlDiagnosticListener(string name) + { + } + + public IDisposable Subscribe(IObserver> observer) + { + throw new NotSupportedException(); + } + + public bool IsEnabled() + { + return false; + } + + public bool IsEnabled(string name) + { + return false; + } + + internal void Write(string sqlBeforeExecuteCommand, object p) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs index c43c10471c..0021538d70 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs @@ -367,8 +367,7 @@ internal SqlInternalConnectionTds( SessionData reconnectSessionData = null, bool applyTransientFaultHandling = false, string accessToken = null, - DbConnectionPool pool = null, - SqlAuthenticationProviderManager sqlAuthProviderManager = null + DbConnectionPool pool = null ) : base(connectionOptions) { @@ -403,7 +402,7 @@ internal SqlInternalConnectionTds( } _activeDirectoryAuthTimeoutRetryHelper = new ActiveDirectoryAuthenticationTimeoutRetryHelper(); - _sqlAuthenticationProviderManager = sqlAuthProviderManager ?? SqlAuthenticationProviderManager.Instance; + _sqlAuthenticationProviderManager = SqlAuthenticationProviderManager.Instance; _identity = identity; Debug.Assert(newSecurePassword != null || newPassword != null, "cannot have both new secure change password and string based change password to be null"); @@ -1753,8 +1752,7 @@ private void AttemptOneLogin( ConnectionOptions.TrustServerCertificate, ConnectionOptions.IntegratedSecurity, withFailover, - ConnectionOptions.Authentication, - _sqlAuthenticationProviderManager); + ConnectionOptions.Authentication); _timeoutErrorInternal.EndPhase(SqlConnectionTimeoutErrorPhase.ConsumePreLoginHandshake); _timeoutErrorInternal.SetAndBeginPhase(SqlConnectionTimeoutErrorPhase.LoginBegin); diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlTransaction.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlTransaction.cs index fb34462779..4a936b4c7c 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlTransaction.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlTransaction.cs @@ -14,8 +14,7 @@ namespace Microsoft.Data.SqlClient /// public sealed class SqlTransaction : DbTransaction { - private static readonly DiagnosticListener s_diagnosticListener = new DiagnosticListener(SqlClientDiagnosticListenerExtensions.DiagnosticListenerName); - + private static readonly SqlDiagnosticListener s_diagnosticListener = new SqlDiagnosticListener(SqlClientDiagnosticListenerExtensions.DiagnosticListenerName); private static int _objectTypeCount; // EventSource Counter internal readonly int _objectID = System.Threading.Interlocked.Increment(ref _objectTypeCount); internal readonly IsolationLevel _isolationLevel = IsolationLevel.ReadCommitted; @@ -350,4 +349,3 @@ private void ZombieCheck() } } } - diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs index 02f05a7822..07c5c56a7c 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs @@ -344,8 +344,7 @@ internal void Connect( bool trustServerCert, bool integratedSecurity, bool withFailover, - SqlAuthenticationMethod authType, - SqlAuthenticationProviderManager sqlAuthProviderManager) + SqlAuthenticationMethod authType) { if (_state != TdsParserState.Closed) { diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs index eb42d38f1a..5a778a1b43 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs @@ -363,9 +363,7 @@ internal SqlInternalConnectionTds( DbConnectionPool pool = null, string accessToken = null, SqlClientOriginalNetworkAddressInfo originalNetworkAddressInfo = null, - bool applyTransientFaultHandling = false, - SqlAuthenticationProviderManager sqlAuthProviderManager = null - ) : base(connectionOptions) + bool applyTransientFaultHandling = false) : base(connectionOptions) { #if DEBUG @@ -421,7 +419,7 @@ internal SqlInternalConnectionTds( } _activeDirectoryAuthTimeoutRetryHelper = new ActiveDirectoryAuthenticationTimeoutRetryHelper(); - _sqlAuthenticationProviderManager = sqlAuthProviderManager ?? SqlAuthenticationProviderManager.Instance; + _sqlAuthenticationProviderManager = SqlAuthenticationProviderManager.Instance; _serverCallback = serverCallback; _clientCallback = clientCallback; @@ -2203,8 +2201,7 @@ private void AttemptOneLogin(ServerInfo serverInfo, string newPassword, SecureSt _serverCallback, _clientCallback, _originalNetworkAddressInfo != null, - disableTnir, - _sqlAuthenticationProviderManager); + disableTnir); timeoutErrorInternal.EndPhase(SqlConnectionTimeoutErrorPhase.ConsumePreLoginHandshake); timeoutErrorInternal.SetAndBeginPhase(SqlConnectionTimeoutErrorPhase.LoginBegin); diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs index 3ebf40d816..f23859b523 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs @@ -483,8 +483,7 @@ internal void Connect(ServerInfo serverInfo, ServerCertificateValidationCallback serverCallback, ClientCertificateRetrievalCallback clientCallback, bool useOriginalAddressInfo, - bool disableTnir, - SqlAuthenticationProviderManager sqlAuthProviderManager) + bool disableTnir) { if (_state != TdsParserState.Closed) { diff --git a/tools/specs/Microsoft.Data.SqlClient.nuspec b/tools/specs/Microsoft.Data.SqlClient.nuspec index 5466991bb1..b4aaf443ac 100644 --- a/tools/specs/Microsoft.Data.SqlClient.nuspec +++ b/tools/specs/Microsoft.Data.SqlClient.nuspec @@ -60,7 +60,6 @@ When using NuGet 3.x this package requires at least version 3.4. -