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 555cbc051c..e00bfbef4a 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 @@ -2304,13 +2304,6 @@ private static void ChangePassword(string connectionString, SqlConnectionString SqlConnectionFactory.SingletonInstance.ClearPool(key); } - // - // SQL DEBUGGING SUPPORT - // - - // this only happens once per connection - // SxS: using named file mapping APIs - internal Task RegisterForConnectionCloseNotification(Task outerTask, object value, int tag) { // Connection exists, schedule removal, will be added to ref collection after calling ValidateAndReconnect 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 006a66b48f..d0a0f50ccc 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj @@ -100,9 +100,6 @@ - - Interop\AdvApi32\AdvApi32.netfx.cs - Interop\Kernel32\FileTypes.cs diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlCommand.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlCommand.cs index f39f91fcd4..f66d9a811d 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlCommand.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlCommand.cs @@ -5620,9 +5620,6 @@ private SqlDataReader RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavi optionSettings = GetResetOptionsString(cmdBehavior); } - // turn debugging on - _activeConnection.CheckSQLDebug(); - // execute sp Debug.Assert(_rpcArrayOf1[0] == rpc); writeTask = _stateObj.Parser.TdsExecuteRPC(this, _rpcArrayOf1, timeout, inSchema, this.Notification, _stateObj, CommandType.StoredProcedure == CommandType, sync: !asyncWrite); diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnection.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnection.cs index 81bbb1ea85..8f22bfc0a1 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnection.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnection.cs @@ -24,10 +24,8 @@ using System.Text; using System.Threading; using System.Threading.Tasks; -using Interop.Windows.AdvApi32; using Microsoft.Data.ProviderBase; using Microsoft.SqlServer.Server; -using Interop.Windows.Kernel32; [assembly: InternalsVisibleTo("System.Data.DataSetExtensions, PublicKey=" + Microsoft.Data.SqlClient.AssemblyRef.EcmaPublicKeyFull)] // DevDiv Bugs 92166 // NOTE: The current Microsoft.VSDesigner editor attributes are implemented for System.Data.SqlClient, and are not publicly available. @@ -284,8 +282,6 @@ internal List GetColumnEncryptionCustomKeyStoreProvidersNames() return new List(0); } - private SqlDebugContext _sdc; // SQL Debugging support - private bool _AsyncCommandInProgress; // SQLStatistics support @@ -1522,14 +1518,12 @@ override public void Close() { SqlClientEventSource.Log.TryCorrelationTraceEvent(" ObjectID {0}, ActivityID {1}", ObjectID, ActivityCorrelator.Current); + SqlStatistics statistics = null; + + TdsParser bestEffortCleanupTarget = null; + RuntimeHelpers.PrepareConstrainedRegions(); try { - SqlStatistics statistics = null; - - TdsParser bestEffortCleanupTarget = null; - RuntimeHelpers.PrepareConstrainedRegions(); - try - { #if DEBUG TdsParser.ReliabilitySection tdsReliabilitySection = new TdsParser.ReliabilitySection(); @@ -1540,72 +1534,62 @@ override public void Close() #else { #endif //DEBUG - bestEffortCleanupTarget = SqlInternalConnection.GetBestEffortCleanupTarget(this); - statistics = SqlStatistics.StartTimer(Statistics); + bestEffortCleanupTarget = SqlInternalConnection.GetBestEffortCleanupTarget(this); + statistics = SqlStatistics.StartTimer(Statistics); - Task reconnectTask = _currentReconnectionTask; - if (reconnectTask != null && !reconnectTask.IsCompleted) + Task reconnectTask = _currentReconnectionTask; + if (reconnectTask != null && !reconnectTask.IsCompleted) + { + CancellationTokenSource cts = _reconnectionCancellationSource; + if (cts != null) { - CancellationTokenSource cts = _reconnectionCancellationSource; - if (cts != null) - { - cts.Cancel(); - } - AsyncHelper.WaitForCompletion(reconnectTask, 0, null, rethrowExceptions: false); // we do not need to deal with possible exceptions in reconnection - if (State != ConnectionState.Open) - {// if we cancelled before the connection was opened - OnStateChange(DbConnectionInternal.StateChangeClosed); - } + cts.Cancel(); } - CancelOpenAndWait(); - CloseInnerConnection(); - GC.SuppressFinalize(this); - - if (Statistics != null) - { - _statistics._closeTimestamp = ADP.TimerCurrent(); + AsyncHelper.WaitForCompletion(reconnectTask, 0, null, rethrowExceptions: false); // we do not need to deal with possible exceptions in reconnection + if (State != ConnectionState.Open) + {// if we cancelled before the connection was opened + OnStateChange(DbConnectionInternal.StateChangeClosed); } } + CancelOpenAndWait(); + CloseInnerConnection(); + GC.SuppressFinalize(this); + + if (Statistics != null) + { + _statistics._closeTimestamp = ADP.TimerCurrent(); + } + } #if DEBUG finally { tdsReliabilitySection.Stop(); } #endif //DEBUG - } - catch (System.OutOfMemoryException e) - { - Abort(e); - throw; - } - catch (System.StackOverflowException e) - { - Abort(e); - throw; - } - catch (System.Threading.ThreadAbortException e) - { - Abort(e); - SqlInternalConnection.BestEffortCleanup(bestEffortCleanupTarget); - throw; - } - finally - { - SqlStatistics.StopTimer(statistics); - //dispose windows identity once connection is closed. - if (_lastIdentity != null) - { - _lastIdentity.Dispose(); - } - } + } + catch (System.OutOfMemoryException e) + { + Abort(e); + throw; + } + catch (System.StackOverflowException e) + { + Abort(e); + throw; + } + catch (System.Threading.ThreadAbortException e) + { + Abort(e); + SqlInternalConnection.BestEffortCleanup(bestEffortCleanupTarget); + throw; } finally { - SqlDebugContext sdc = _sdc; - _sdc = null; - if (sdc != null) + SqlStatistics.StopTimer(statistics); + //dispose windows identity once connection is closed. + if (_lastIdentity != null) { - sdc.Dispose(); + _lastIdentity.Dispose(); } } } @@ -2206,7 +2190,6 @@ private bool TryOpenInner(TaskCompletionSource retry) tdsInnerConnection.Parser.Statistics = null; _statistics = null; // in case of previous Open/Close/reset_CollectStats sequence } - CompleteOpen(); } } #if DEBUG @@ -2411,40 +2394,6 @@ internal void OnError(SqlException exception, bool breakConnection, Action public static void ChangePassword(string connectionString, string newPassword) { @@ -2880,23 +2642,6 @@ internal Task RegisterForConnectionCloseNotification(Task outerTask, ob ).Unwrap(); } - - // updates our context with any changes made to the memory-mapped data by an external process - static private void RefreshMemoryMappedData(SqlDebugContext sdc) - { - Debug.Assert(ADP.s_ptrZero != sdc.pMemMap, "SQL Debug: invalid null value for pMemMap!"); - // copy memory mapped file contents into managed types - MEMMAP memMap = (MEMMAP)Marshal.PtrToStructure(sdc.pMemMap, typeof(MEMMAP)); - sdc.dbgpid = memMap.dbgpid; - sdc.fOption = (memMap.fOption == 1) ? true : false; - // xlate ansi byte[] -> managed strings - Encoding cp = System.Text.Encoding.GetEncoding(TdsEnums.DEFAULT_ENGLISH_CODE_PAGE_VALUE); - sdc.machineName = cp.GetString(memMap.rgbMachineName, 0, memMap.rgbMachineName.Length); - sdc.sdiDllName = cp.GetString(memMap.rgbDllName, 0, memMap.rgbDllName.Length); - // just get data reference - sdc.data = memMap.rgbData; - } - /// public void ResetStatistics() { @@ -3066,73 +2811,4 @@ internal byte[] GetBytes(object o, out Format format, out int maxSize) return retval; } } // SqlConnection - - sealed class SqlDebugContext : IDisposable - { - // context data - internal uint pid = 0; - internal uint tid = 0; - internal bool active = false; - // memory-mapped data - internal IntPtr pMemMap = ADP.s_ptrZero; - internal IntPtr hMemMap = ADP.s_ptrZero; - internal uint dbgpid = 0; - internal bool fOption = false; - internal string machineName = null; - internal string sdiDllName = null; - internal byte[] data = null; - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - // using CloseHandle and UnmapViewOfFile - no exposure - [ResourceExposure(ResourceScope.None)] - [ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)] - private void Dispose(bool disposing) - { - if (disposing) - { - // Nothing to do here - ; - } - if (pMemMap != IntPtr.Zero) - { - Kernel32.UnmapViewOfFile(pMemMap); - pMemMap = IntPtr.Zero; - } - if (hMemMap != IntPtr.Zero) - { - Kernel32.CloseHandle(hMemMap); - hMemMap = IntPtr.Zero; - } - active = false; - } - - ~SqlDebugContext() - { - Dispose(false); - } - - } - - // native interop memory mapped structure for sdi debugging - [StructLayoutAttribute(LayoutKind.Sequential, Pack = 1)] - internal struct MEMMAP - { - [MarshalAs(UnmanagedType.U4)] - internal uint dbgpid; // id of debugger - [MarshalAs(UnmanagedType.U4)] - internal uint fOption; // 1 - start debugging, 0 - stop debugging - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] - internal byte[] rgbMachineName; - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] - internal byte[] rgbDllName; - [MarshalAs(UnmanagedType.U4)] - internal uint cbData; - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 255)] - internal byte[] rgbData; - } } // Microsoft.Data.SqlClient namespace diff --git a/src/Microsoft.Data.SqlClient/src/Interop/Windows/AdvApi32/AdvApi32.netfx.cs b/src/Microsoft.Data.SqlClient/src/Interop/Windows/AdvApi32/AdvApi32.netfx.cs deleted file mode 100644 index 3522cb3625..0000000000 --- a/src/Microsoft.Data.SqlClient/src/Interop/Windows/AdvApi32/AdvApi32.netfx.cs +++ /dev/null @@ -1,63 +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 System; -using System.Runtime.InteropServices; -using System.Runtime.Versioning; - -namespace Interop.Windows.AdvApi32 -{ - internal class AdvApi32 - { - private const string DllName = "advapi32.dll"; - - [DllImport(DllName, ExactSpelling = true, CharSet = CharSet.Auto, SetLastError = true)] - [ResourceExposure(ResourceScope.None)] - internal static extern bool AddAccessAllowedAce(IntPtr pAcl, int dwAceRevision, uint AccessMask, IntPtr pSid); - - [DllImport(DllName, ExactSpelling = true, CharSet = CharSet.Auto, SetLastError = true)] - [ResourceExposure(ResourceScope.None)] - internal static extern bool AddAccessDeniedAce(IntPtr pAcl, int dwAceRevision, int AccessMask, IntPtr pSid); - - [DllImport(DllName, ExactSpelling = true, CharSet = CharSet.Auto, SetLastError = true)] - [ResourceExposure(ResourceScope.None)] - internal static extern bool AllocateAndInitializeSid( - IntPtr pIdentifierAuthority, - byte nSubAuthorityCount, - int dwSubAuthority0, - int dwSubAuthority1, - int dwSubAuthority2, - int dwSubAuthority3, - int dwSubAuthority4, - int dwSubAuthority5, - int dwSubAuthority6, - int dwSubAuthority7, - ref IntPtr pSid); - - - [DllImport(DllName, ExactSpelling = true, CharSet = CharSet.Auto, SetLastError = true)] - [ResourceExposure(ResourceScope.None)] - internal static extern IntPtr FreeSid(IntPtr pSid); - - [DllImport(DllName, ExactSpelling = true, CharSet = CharSet.Auto, SetLastError = true)] - [ResourceExposure(ResourceScope.None)] - internal static extern int GetLengthSid(IntPtr pSid); - - [DllImport(DllName, ExactSpelling = true, CharSet = CharSet.Auto, SetLastError = true)] - [ResourceExposure(ResourceScope.None)] - internal static extern bool InitializeAcl(IntPtr pAcl, int nAclLength, int dwAclRevision); - - [DllImport(DllName, ExactSpelling = true, CharSet = CharSet.Auto, SetLastError = true)] - [ResourceExposure(ResourceScope.None)] - internal static extern bool InitializeSecurityDescriptor(IntPtr pSecurityDescriptor, int dwRevision); - - [DllImport(DllName, ExactSpelling = true, CharSet = CharSet.Auto, SetLastError = true)] - [ResourceExposure(ResourceScope.None)] - internal static extern bool SetSecurityDescriptorDacl( - IntPtr pSecurityDescriptor, - bool bDaclPresent, - IntPtr pDacl, - bool bDaclDefaulted); - } -} diff --git a/src/Microsoft.Data.SqlClient/src/Interop/Windows/Kernel32/Kernel32.cs b/src/Microsoft.Data.SqlClient/src/Interop/Windows/Kernel32/Kernel32.cs index 14bf43397a..530838ba38 100644 --- a/src/Microsoft.Data.SqlClient/src/Interop/Windows/Kernel32/Kernel32.cs +++ b/src/Microsoft.Data.SqlClient/src/Interop/Windows/Kernel32/Kernel32.cs @@ -44,27 +44,6 @@ internal static uint CtlCode(ushort deviceType, ushort function, byte method, by return (uint)((deviceType << 16) | (access << 14) | (function << 2) | method); } - #if NETFRAMEWORK - [DllImport(DllName, ExactSpelling = true, CharSet = CharSet.Auto, SetLastError = true)] - [ResourceExposure(ResourceScope.Machine)] - internal static extern bool CloseHandle(IntPtr handle); - #endif - - #if NETFRAMEWORK - // CreateFileMappingA contains a security venerability, in the unicode->ansi conversion - // Its possible to spoof the directory and construct ../ sequences, See FxCop Warning - // Specify marshaling for pinvoke string arguments - [DllImport(DllName, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)] - [ResourceExposure(ResourceScope.Machine)] - internal static extern IntPtr CreateFileMappingA( - IntPtr hFile, - IntPtr pAttr, - int flProtect, - int dwMaximumSizeHigh, - int dwMaximumSizeLow, - [MarshalAs(UnmanagedType.LPStr)] string lpName); - #endif - [DllImport(DllName, CharSet = CharSet.Unicode, SetLastError = true)] internal static extern bool DeviceIoControl( SafeFileHandle fileHandle, @@ -109,36 +88,7 @@ internal static extern int GetFullPathName( public static extern SafeLibraryHandle LoadLibraryExW([In] string lpwLibFileName, [In] IntPtr hFile, [In] uint dwFlags); #endif - #if NETFRAMEWORK - [DllImport(DllName, ExactSpelling = true, CharSet = CharSet.Auto)] - [ResourceExposure(ResourceScope.Machine)] - internal static extern IntPtr MapViewOfFile( - IntPtr hFileMappingObject, - int dwDesiredAccess, - int dwFileOffsetHigh, - int dwFileOffsetLow, - IntPtr dwNumberOfBytesToMap); - #endif - - #if NETFRAMEWORK - // OpenFileMappingA contains a security venerability, in the unicode->ansi conversion - // Its possible to spoof the directory and construct ../ sequences, See FxCop Warning - // Specify marshaling for pinvoke string arguments - [DllImport(DllName, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)] - [ResourceExposure(ResourceScope.Machine)] - internal static extern IntPtr OpenFileMappingA( - int dwDesiredAccess, - bool bInheritHandle, - [MarshalAs(UnmanagedType.LPStr)] string lpName); - #endif - [DllImport(DllName, SetLastError = true, ExactSpelling = true)] internal static extern bool SetThreadErrorMode(uint dwNewMode, out uint lpOldMode); - - #if NETFRAMEWORK - [DllImport(DllName, ExactSpelling = true, CharSet = CharSet.Auto)] - [ResourceExposure(ResourceScope.Machine)] - internal static extern bool UnmapViewOfFile(IntPtr lpBaseAddress); - #endif } }