diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObject.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObject.cs index e579500c84..35395ace1b 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObject.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObject.cs @@ -398,7 +398,7 @@ public bool TryReadByteArray(Span buff, int len, out int totalRead) Debug.Assert(bytesToRead > 0, "0 byte read in TryReadByteArray"); if (!buff.IsEmpty) { - var copyFrom = new ReadOnlySpan(_inBuff, _inBytesUsed, bytesToRead); + ReadOnlySpan copyFrom = new ReadOnlySpan(_inBuff, _inBytesUsed, bytesToRead); Span copyTo = buff.Slice(totalRead, bytesToRead); copyFrom.CopyTo(copyTo); } @@ -1292,7 +1292,7 @@ internal void OnConnectionClosed() Interlocked.MemoryBarrier(); // then check for networkPacketTaskSource - var taskSource = _networkPacketTaskSource; + TaskCompletionSource taskSource = _networkPacketTaskSource; if (taskSource != null) { taskSource.TrySetException(ADP.ExceptionWithStackTrace(ADP.ClosedConnectionError())); @@ -2055,7 +2055,7 @@ public void WriteAsyncCallback(IntPtr key, PacketHandle packet, uint sniError) } catch (Exception e) { - var writeCompletionSource = _writeCompletionSource; + TaskCompletionSource writeCompletionSource = _writeCompletionSource; if (writeCompletionSource != null) { writeCompletionSource.TrySetException(e); @@ -2071,7 +2071,7 @@ public void WriteAsyncCallback(IntPtr key, PacketHandle packet, uint sniError) writeCompletionSource = _writeCompletionSource; if (writeCompletionSource != null) { - var delayedException = Interlocked.Exchange(ref _delayedWriteAsyncCallbackException, null); + Exception delayedException = Interlocked.Exchange(ref _delayedWriteAsyncCallbackException, null); if (delayedException != null) { writeCompletionSource.TrySetException(delayedException); @@ -2095,7 +2095,7 @@ public void WriteAsyncCallback(IntPtr key, PacketHandle packet, uint sniError) new Timer(obj => { Interlocked.Decrement(ref _asyncWriteCount); - var writeCompletionSource = _writeCompletionSource; + TaskCompletionSource writeCompletionSource = _writeCompletionSource; if (_asyncWriteCount == 0 && writeCompletionSource != null) { writeCompletionSource.TrySetResult(null); @@ -2116,7 +2116,7 @@ public void WriteAsyncCallback(IntPtr key, PacketHandle packet, uint sniError) return; } #endif - var completionSource = _writeCompletionSource; + TaskCompletionSource completionSource = _writeCompletionSource; if (_asyncWriteCount == 0 && completionSource != null) { completionSource.TrySetResult(null); @@ -2158,7 +2158,7 @@ internal void ResetSecurePasswordsInformation() internal Task WaitForAccumulatedWrites() { // Checked for stored exceptions - var delayedException = Interlocked.Exchange(ref _delayedWriteAsyncCallbackException, null); + Exception delayedException = Interlocked.Exchange(ref _delayedWriteAsyncCallbackException, null); if (delayedException != null) { throw delayedException; @@ -2449,7 +2449,7 @@ private void CancelWritePacket() private Task SNIWritePacket(PacketHandle packet, out uint sniError, bool canAccumulate, bool callerHasConnectionLock, bool asyncClose = false) { // Check for a stored exception - var delayedException = Interlocked.Exchange(ref _delayedWriteAsyncCallbackException, null); + Exception delayedException = Interlocked.Exchange(ref _delayedWriteAsyncCallbackException, null); if (delayedException != null) { throw delayedException; @@ -2998,7 +2998,7 @@ internal void CheckThrowSNIException() internal void AssertStateIsClean() { // If our TdsParser is closed or broken, then we don't really care about our state - var parser = _parser; + TdsParser parser = _parser; if ((parser != null) && (parser.State != TdsParserState.Closed) && (parser.State != TdsParserState.Broken)) { // Async reads @@ -3020,8 +3020,8 @@ internal void AssertStateIsClean() #if DEBUG internal void CompletePendingReadWithSuccess(bool resetForcePendingReadsToWait) { - var realNetworkPacketTaskSource = _realNetworkPacketTaskSource; - var networkPacketTaskSource = _networkPacketTaskSource; + TaskCompletionSource realNetworkPacketTaskSource = _realNetworkPacketTaskSource; + TaskCompletionSource networkPacketTaskSource = _networkPacketTaskSource; Debug.Assert(s_forcePendingReadsToWaitForUser, "Not forcing pends to wait for user - can't force complete"); Debug.Assert(networkPacketTaskSource != null, "No pending read to complete"); @@ -3050,8 +3050,8 @@ internal void CompletePendingReadWithSuccess(bool resetForcePendingReadsToWait) internal void CompletePendingReadWithFailure(int errorCode, bool resetForcePendingReadsToWait) { - var realNetworkPacketTaskSource = _realNetworkPacketTaskSource; - var networkPacketTaskSource = _networkPacketTaskSource; + TaskCompletionSource realNetworkPacketTaskSource = _realNetworkPacketTaskSource; + TaskCompletionSource networkPacketTaskSource = _networkPacketTaskSource; Debug.Assert(s_forcePendingReadsToWaitForUser, "Not forcing pends to wait for user - can't force complete"); Debug.Assert(networkPacketTaskSource != null, "No pending read to complete"); diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParserStateObject.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParserStateObject.cs index 01312b80ed..698adfe5d1 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParserStateObject.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParserStateObject.cs @@ -1389,7 +1389,7 @@ internal void OnConnectionClosed() Thread.MemoryBarrier(); // then check for networkPacketTaskSource - var taskSource = _networkPacketTaskSource; + TaskCompletionSource taskSource = _networkPacketTaskSource; if (taskSource != null) { taskSource.TrySetException(ADP.ExceptionWithStackTrace(ADP.ClosedConnectionError())); @@ -2141,7 +2141,7 @@ public void WriteAsyncCallback(IntPtr key, IntPtr packet, uint sniError) } catch (Exception e) { - var writeCompletionSource = _writeCompletionSource; + TaskCompletionSource writeCompletionSource = _writeCompletionSource; if (writeCompletionSource != null) { writeCompletionSource.TrySetException(e); @@ -2157,7 +2157,7 @@ public void WriteAsyncCallback(IntPtr key, IntPtr packet, uint sniError) writeCompletionSource = _writeCompletionSource; if (writeCompletionSource != null) { - var delayedException = Interlocked.Exchange(ref _delayedWriteAsyncCallbackException, null); + Exception delayedException = Interlocked.Exchange(ref _delayedWriteAsyncCallbackException, null); if (delayedException != null) { writeCompletionSource.TrySetException(delayedException); @@ -2181,7 +2181,7 @@ public void WriteAsyncCallback(IntPtr key, IntPtr packet, uint sniError) new Timer(obj => { Interlocked.Decrement(ref _asyncWriteCount); - var writeCompletionSource = _writeCompletionSource; + TaskCompletionSource writeCompletionSource = _writeCompletionSource; if (_asyncWriteCount == 0 && writeCompletionSource != null) { writeCompletionSource.TrySetResult(null); @@ -2202,7 +2202,7 @@ public void WriteAsyncCallback(IntPtr key, IntPtr packet, uint sniError) return; } #endif - var completionSource = _writeCompletionSource; + TaskCompletionSource completionSource = _writeCompletionSource; if (_asyncWriteCount == 0 && completionSource != null) { completionSource.TrySetResult(null); @@ -2258,7 +2258,7 @@ internal Task WaitForAccumulatedWrites() { // Checked for stored exceptions #pragma warning disable 420 // A reference to a volatile field will not be treated as volatile - Disabling since the Interlocked APIs are volatile aware - var delayedException = Interlocked.Exchange(ref _delayedWriteAsyncCallbackException, null); + Exception delayedException = Interlocked.Exchange(ref _delayedWriteAsyncCallbackException, null); if (delayedException != null) { throw delayedException; @@ -2517,7 +2517,7 @@ private void CancelWritePacket() private Task SNIWritePacket(SNIHandle handle, SNIPacket packet, out uint sniError, bool canAccumulate, bool callerHasConnectionLock, bool asyncClose = false) { // Check for a stored exception - var delayedException = Interlocked.Exchange(ref _delayedWriteAsyncCallbackException, null); + Exception delayedException = Interlocked.Exchange(ref _delayedWriteAsyncCallbackException, null); if (delayedException != null) { throw delayedException; @@ -3163,7 +3163,7 @@ internal void CheckThrowSNIException() internal void AssertStateIsClean() { // If our TdsParser is closed or broken, then we don't really care about our state - var parser = _parser; + TdsParser parser = _parser; if ((parser != null) && (parser.State != TdsParserState.Closed) && (parser.State != TdsParserState.Broken)) { // Async reads @@ -3185,8 +3185,8 @@ internal void AssertStateIsClean() #if DEBUG internal void CompletePendingReadWithSuccess(bool resetForcePendingReadsToWait) { - var realNetworkPacketTaskSource = _realNetworkPacketTaskSource; - var networkPacketTaskSource = _networkPacketTaskSource; + TaskCompletionSource realNetworkPacketTaskSource = _realNetworkPacketTaskSource; + TaskCompletionSource networkPacketTaskSource = _networkPacketTaskSource; Debug.Assert(s_forcePendingReadsToWaitForUser, "Not forcing pends to wait for user - can't force complete"); Debug.Assert(networkPacketTaskSource != null, "No pending read to complete"); @@ -3215,8 +3215,8 @@ internal void CompletePendingReadWithSuccess(bool resetForcePendingReadsToWait) internal void CompletePendingReadWithFailure(int errorCode, bool resetForcePendingReadsToWait) { - var realNetworkPacketTaskSource = _realNetworkPacketTaskSource; - var networkPacketTaskSource = _networkPacketTaskSource; + TaskCompletionSource realNetworkPacketTaskSource = _realNetworkPacketTaskSource; + TaskCompletionSource networkPacketTaskSource = _networkPacketTaskSource; Debug.Assert(s_forcePendingReadsToWaitForUser, "Not forcing pends to wait for user - can't force complete"); Debug.Assert(networkPacketTaskSource != null, "No pending read to complete");