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 b2c1017fc1..77c2150b7b 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -659,6 +659,9 @@ + + Microsoft\Data\SqlClient\TdsParserSafeHandles.Windows.cs + @@ -744,7 +747,6 @@ - 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 93b2fe8ca9..1c4f848df9 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj @@ -554,6 +554,9 @@ Microsoft\Data\SqlClient\TdsParameterSetter.cs + + Microsoft\Data\SqlClient\TdsParserSafeHandles.Windows.cs + Microsoft\Data\SqlClient\TdsParserStaticMethods.cs @@ -648,7 +651,6 @@ - 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 664c6e56d5..1ecb6c6ce8 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 @@ -521,7 +521,7 @@ internal void Connect(ServerInfo serverInfo, // Clean up IsSQLDNSCachingSupported flag from previous status _connHandler.IsSQLDNSCachingSupported = false; - UInt32 sniStatus = SNILoadHandle.SingletonInstance.SNIStatus; + UInt32 sniStatus = SNILoadHandle.SingletonInstance.Status; if (sniStatus != TdsEnums.SNI_SUCCESS) { _physicalStateObj.AddError(ProcessSNIError(_physicalStateObj)); diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserSafeHandles.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserSafeHandles.Windows.cs similarity index 85% rename from src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserSafeHandles.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserSafeHandles.Windows.cs index 3db0f07fcf..8d2716c63e 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserSafeHandles.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserSafeHandles.Windows.cs @@ -5,8 +5,12 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading; +#if NETFRAMEWORK +using Microsoft.Data.Common; +#endif namespace Microsoft.Data.SqlClient { @@ -23,7 +27,7 @@ internal sealed partial class SNILoadHandle : SafeHandle private SNILoadHandle() : base(IntPtr.Zero, true) { - // From security review - SafeHandle guarantees this is only called once. + // SQL BU DT 346588 - from security review - SafeHandle guarantees this is only called once. // The reason for the safehandle is guaranteed initialization and termination of SNI to // ensure SNI terminates and cleans up properly. try @@ -49,7 +53,7 @@ public bool ClientOSEncryptionSupport { try { - UInt32 value = 0; + uint value = 0; // Query OS to find out whether encryption is supported. SNINativeMethodWrapper.SNIQueryInfo(SNINativeMethodWrapper.QTypes.SNI_QUERY_CLIENT_ENCRYPT_POSSIBLE, ref value); _clientOSEncryptionSupport = value != 0; @@ -101,7 +105,11 @@ private static void ReadDispatcher(IntPtr key, IntPtr packet, uint error) if (null != stateObj) { +#if NETFRAMEWORK + stateObj.ReadAsyncCallback(IntPtr.Zero, packet, error); +#else stateObj.ReadAsyncCallback(IntPtr.Zero, PacketHandle.FromNativePointer(packet), error); +#endif // NETFRAMEWORK } } } @@ -122,7 +130,11 @@ private static void WriteDispatcher(IntPtr key, IntPtr packet, uint error) if (null != stateObj) { +#if NETFRAMEWORK + stateObj.WriteAsyncCallback(IntPtr.Zero, packet, error); +#else stateObj.WriteAsyncCallback(IntPtr.Zero, PacketHandle.FromNativePointer(packet), error); +#endif // NETFRAMEWORK } } } @@ -144,12 +156,17 @@ internal SNIHandle( bool flushCache, bool fSync, bool fParallel, +#if NETFRAMEWORK + TransparentNetworkResolutionState transparentNetworkResolutionState, + int totalTimeout, +#endif SqlConnectionIPAddressPreference ipPreference, SQLDNSInfo cachedDNSInfo, bool tlsFirst, string hostNameInCertificate) : base(IntPtr.Zero, true) { + RuntimeHelpers.PrepareConstrainedRegions(); try { } finally @@ -158,11 +175,21 @@ internal SNIHandle( instanceName = new byte[256]; // Size as specified by netlibs. if (ignoreSniOpenTimeout) { + // UNDONE: ITEM12001110 (DB Mirroring Reconnect) Old behavior of not truly honoring timeout presevered + // for non-failover scenarios to avoid breaking changes as part of a QFE. Consider fixing timeout + // handling in next full release and removing ignoreSniOpenTimeout parameter. timeout = Timeout.Infinite; // -1 == native SNIOPEN_TIMEOUT_VALUE / INFINITE } - _status = SNINativeMethodWrapper.SNIOpenSyncEx(myInfo, serverName, ref base.handle, spnBuffer, instanceName, flushCache, - fSync, timeout, fParallel, ipPreference, cachedDNSInfo, hostNameInCertificate); +#if NETFRAMEWORK + int transparentNetworkResolutionStateNo = (int)transparentNetworkResolutionState; + _status = SNINativeMethodWrapper.SNIOpenSyncEx(myInfo, serverName, ref base.handle, + spnBuffer, instanceName, flushCache, fSync, timeout, fParallel, transparentNetworkResolutionStateNo, totalTimeout, + ADP.IsAzureSqlServerEndpoint(serverName), ipPreference, cachedDNSInfo, hostNameInCertificate); +#else + _status = SNINativeMethodWrapper.SNIOpenSyncEx(myInfo, serverName, ref base.handle, + spnBuffer, instanceName, flushCache, fSync, timeout, fParallel, ipPreference, cachedDNSInfo, hostNameInCertificate); +#endif // NETFRAMEWORK } }