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 4a1e9a7742..8adc60285f 100644
--- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj
+++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj
@@ -229,6 +229,9 @@
Microsoft\Data\SqlClient\SqlCommandSet.cs
+
+ Microsoft\Data\SqlClient\SqlConnectionPoolGroupProviderInfo.cs
+
Microsoft\Data\SqlClient\SqlConnectionPoolProviderInfo.cs
@@ -504,7 +507,6 @@
-
diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionPoolGroupProviderInfo.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionPoolGroupProviderInfo.cs
deleted file mode 100644
index 5a88dee38b..0000000000
--- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionPoolGroupProviderInfo.cs
+++ /dev/null
@@ -1,91 +0,0 @@
-// 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 Microsoft.Data.ProviderBase;
-
-namespace Microsoft.Data.SqlClient
-{
- sealed internal class SqlConnectionPoolGroupProviderInfo : DbConnectionPoolGroupProviderInfo
- {
- private string _alias;
- 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 (string.IsNullOrEmpty(_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)
- {
- SqlClientEventSource.Log.TryTraceEvent("SqlConnectionPoolGroupProviderInfo.AliasCheck | Info | Alias change detected. Clearing PoolGroup.");
- base.PoolGroup.Clear();
- _alias = server;
- }
- }
- }
- }
-
-
- internal void FailoverCheck(SqlInternalConnection connection, bool actualUseFailoverPartner, SqlConnectionString userConnectionOptions, string actualFailoverPartner)
- {
- if (UseFailoverPartner != actualUseFailoverPartner)
- {
- SqlClientEventSource.Log.TryTraceEvent("SqlConnectionPoolGroupProviderInfo.FailoverCheck | Info | Failover detected. Failover partner '{0}'. Clearing PoolGroup", 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 optimistically generate the permission set to keep
- // lock short, but we only do this when we get a new
- // failover partner.
-
- lock (this)
- {
- if (_failoverPartner != actualFailoverPartner)
- {
- _failoverPartner = actualFailoverPartner;
- }
- }
- }
- }
- }
-}
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 9b85ced97f..484e2233a9 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
@@ -1635,7 +1635,7 @@ private void LoginNoFailover(ServerInfo serverInfo,
// We must wait for CompleteLogin to finish for to have the
// env change from the server to know its designated failover
// partner; save this information in _currentFailoverPartner.
- PoolGroupProviderInfo.FailoverCheck(this, false, connectionOptions, ServerProvidedFailOverPartner);
+ PoolGroupProviderInfo.FailoverCheck(false, connectionOptions, ServerProvidedFailOverPartner);
}
CurrentDataSource = originalServerInfo.UserServerName;
}
@@ -1841,7 +1841,7 @@ TimeoutTimer timeout
// We must wait for CompleteLogin to finish for to have the
// env change from the server to know its designated failover
// partner; save this information in _currentFailoverPartner.
- PoolGroupProviderInfo.FailoverCheck(this, useFailoverHost, connectionOptions, ServerProvidedFailOverPartner);
+ PoolGroupProviderInfo.FailoverCheck(useFailoverHost, connectionOptions, ServerProvidedFailOverPartner);
}
CurrentDataSource = (useFailoverHost ? failoverHost : primaryServerInfo.UserServerName);
}
diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj
index d1443d0754..2c826f8021 100644
--- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj
+++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj
@@ -300,6 +300,9 @@
Microsoft\Data\SqlClient\SqlCommandSet.cs
+
+ Microsoft\Data\SqlClient\SqlConnectionPoolGroupProviderInfo.cs
+
Microsoft\Data\SqlClient\SqlConnectionPoolProviderInfo.cs
@@ -471,7 +474,6 @@
-
@@ -640,4 +642,4 @@
-
\ No newline at end of file
+
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 c6844a0568..623ce80d93 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
@@ -1966,7 +1966,7 @@ private void LoginNoFailover(ServerInfo serverInfo, string newPassword, SecureSt
// We must wait for CompleteLogin to finish for to have the
// env change from the server to know its designated failover
// partner; save this information in _currentFailoverPartner.
- PoolGroupProviderInfo.FailoverCheck(this, false, connectionOptions, ServerProvidedFailOverPartner);
+ PoolGroupProviderInfo.FailoverCheck(false, connectionOptions, ServerProvidedFailOverPartner);
}
CurrentDataSource = originalServerInfo.UserServerName;
}
@@ -2235,7 +2235,7 @@ TimeoutTimer timeout
// We must wait for CompleteLogin to finish for to have the
// env change from the server to know its designated failover
// partner; save this information in _currentFailoverPartner.
- PoolGroupProviderInfo.FailoverCheck(this, useFailoverHost, connectionOptions, ServerProvidedFailOverPartner);
+ PoolGroupProviderInfo.FailoverCheck(useFailoverHost, connectionOptions, ServerProvidedFailOverPartner);
}
CurrentDataSource = (useFailoverHost ? failoverHost : primaryServerInfo.UserServerName);
}
diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionPoolGroupProviderInfo.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolGroupProviderInfo.cs
similarity index 70%
rename from src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionPoolGroupProviderInfo.cs
rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolGroupProviderInfo.cs
index 24071a3db1..310aaee04d 100644
--- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionPoolGroupProviderInfo.cs
+++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolGroupProviderInfo.cs
@@ -2,46 +2,36 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using Microsoft.Data.Common;
+using System.Security;
using Microsoft.Data.ProviderBase;
namespace Microsoft.Data.SqlClient
{
- sealed internal class SqlConnectionPoolGroupProviderInfo : DbConnectionPoolGroupProviderInfo
+ internal sealed class SqlConnectionPoolGroupProviderInfo : DbConnectionPoolGroupProviderInfo
{
private string _alias;
- private System.Security.PermissionSet _failoverPermissionSet;
private string _failoverPartner;
private bool _useFailoverPartner;
+#if NETFRAMEWORK
+ private PermissionSet _failoverPermissionSet;
+#endif
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
+ // in the connection string and we have not yet connected to get the
// env change.
_failoverPartner = connectionOptions.FailoverPartner;
- if (ADP.IsEmpty(_failoverPartner))
+ if (string.IsNullOrEmpty(_failoverPartner))
{
_failoverPartner = null;
}
}
- internal string FailoverPartner
- {
- get
- {
- return _failoverPartner;
- }
- }
+ internal string FailoverPartner => _failoverPartner;
- internal bool UseFailoverPartner
- {
- get
- {
- return _useFailoverPartner;
- }
- }
+ internal bool UseFailoverPartner => _useFailoverPartner;
internal void AliasCheck(string server)
{
@@ -55,7 +45,7 @@ internal void AliasCheck(string server)
}
else if (_alias != server)
{
- SqlClientEventSource.Log.TryTraceEvent(" alias change detected. Clearing PoolGroup");
+ SqlClientEventSource.Log.TryTraceEvent("SqlConnectionPoolGroupProviderInfo.AliasCheck | Info | Alias change detected. Clearing PoolGroup.");
base.PoolGroup.Clear();
_alias = server;
}
@@ -63,7 +53,40 @@ internal void AliasCheck(string server)
}
}
- private System.Security.PermissionSet CreateFailoverPermission(SqlConnectionString userConnectionOptions, string actualFailoverPartner)
+ internal void FailoverCheck(bool actualUseFailoverPartner, SqlConnectionString userConnectionOptions, string actualFailoverPartner)
+ {
+ if (UseFailoverPartner != actualUseFailoverPartner)
+ {
+ SqlClientEventSource.Log.TryTraceEvent("SqlConnectionPoolGroupProviderInfo.FailoverCheck | Info | Failover detected. Failover partner '{0}'. Clearing PoolGroup", 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 optimistically generate the permission set to keep
+ // lock short, but we only do this when we get a new
+ // failover partner.
+
+#if NETFRAMEWORK
+ PermissionSet failoverPermissionSet = CreateFailoverPermission(userConnectionOptions, actualFailoverPartner);
+#endif
+ lock (this)
+ {
+ if (_failoverPartner != actualFailoverPartner)
+ {
+ _failoverPartner = actualFailoverPartner;
+#if NETFRAMEWORK
+ _failoverPermissionSet = failoverPermissionSet;
+#endif
+ }
+ }
+ }
+ }
+
+#if NETFRAMEWORK
+ private PermissionSet CreateFailoverPermission(SqlConnectionString userConnectionOptions, string actualFailoverPartner)
{
string keywordToReplace;
@@ -94,45 +117,13 @@ private System.Security.PermissionSet CreateFailoverPermission(SqlConnectionStri
return (new SqlConnectionString(failoverConnectionString)).CreatePermissionSet();
}
- internal void FailoverCheck(SqlInternalConnection connection, bool actualUseFailoverPartner, SqlConnectionString userConnectionOptions, string actualFailoverPartner)
- {
- if (UseFailoverPartner != actualUseFailoverPartner)
- {
- // TODO: will connections in progress somehow be active for two different datasources?
- SqlClientEventSource.Log.TryTraceEvent(" Failover detected. failover partner='{0}'. Clearing PoolGroup", 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.
- // TODO: it seems to me that being optimistic here may not be such a good idea; what if there are 100s of concurrent failovers?
-
- 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;
+ PermissionSet failoverPermissionSet = _failoverPermissionSet;
if (null != failoverPermissionSet)
{
// demand on pooled failover connections
@@ -140,5 +131,6 @@ internal void FailoverPermissionDemand()
}
}
}
+#endif
}
}