diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/AdapterUtil.SqlClient.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/AdapterUtil.SqlClient.cs index da6a069c90..279c310d10 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/AdapterUtil.SqlClient.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/AdapterUtil.SqlClient.cs @@ -757,29 +757,37 @@ internal static Version GetAssemblyVersion() // This method assumes dataSource parameter is in TCP connection string format. internal static bool IsAzureSqlServerEndpoint(string dataSource) { + int length = dataSource.Length; // remove server port - int i = dataSource.LastIndexOf(','); - if (i >= 0) + int foundIndex = dataSource.LastIndexOf(','); + if (foundIndex >= 0) { - dataSource = dataSource.Substring(0, i); + length = foundIndex; } // check for the instance name - i = dataSource.LastIndexOf('\\'); - if (i >= 0) + foundIndex = dataSource.LastIndexOf('\\', length - 1, length - 1); + if (foundIndex > 0) { - dataSource = dataSource.Substring(0, i); + length = foundIndex; } - // trim redundant whitespace - dataSource = dataSource.Trim(); + // trim trailing whitespace + while (length > 0 && char.IsWhiteSpace(dataSource[length - 1])) + { + length -= 1; + } // check if servername end with any azure endpoints - for (i = 0; i < AzureSqlServerEndpoints.Length; i++) + for (int index = 0; index < AzureSqlServerEndpoints.Length; index++) { - if (dataSource.EndsWith(AzureSqlServerEndpoints[i], StringComparison.OrdinalIgnoreCase)) + string endpoint = AzureSqlServerEndpoints[index]; + if (length > endpoint.Length) { - return true; + if (string.Compare(dataSource, length - endpoint.Length, endpoint, 0, endpoint.Length, StringComparison.OrdinalIgnoreCase) == 0) + { + return true; + } } } 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 925f5a4f1b..c2e41d4cb3 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 @@ -135,6 +135,7 @@ public TimeoutState(int value) private volatile int _timeoutIdentityValue; internal volatile bool _attentionSent; // true if we sent an Attention to the server internal volatile bool _attentionSending; + private readonly TimerCallback _onTimeoutAsync; // Below 2 properties are used to enforce timeout delays in code to // reproduce issues related to theadpool starvation and timeout delay. @@ -293,6 +294,7 @@ internal TdsParserStateObject(TdsParser parser) // Construct a physical connection Debug.Assert(null != parser, "no parser?"); _parser = parser; + _onTimeoutAsync = OnTimeoutAsync; // For physical connection, initialize to default login packet size. SetPacketSize(TdsEnums.DEFAULT_LOGIN_PACKET_SIZE); @@ -309,6 +311,7 @@ internal TdsParserStateObject(TdsParser parser, TdsParserStateObject physicalCon // Construct a MARS session Debug.Assert(null != parser, "no parser?"); _parser = parser; + _onTimeoutAsync = OnTimeoutAsync; SniContext = SniContext.Snix_GetMarsSession; Debug.Assert(null != _parser._physicalStateObj, "no physical session?"); @@ -2474,7 +2477,7 @@ internal void ReadSni(TaskCompletionSource completion) _networkPacketTimeout?.Dispose(); _networkPacketTimeout = ADP.UnsafeCreateTimer( - new TimerCallback(OnTimeoutAsync), + _onTimeoutAsync, new TimeoutState(_timeoutIdentityValue), Timeout.Infinite, Timeout.Infinite diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlClientEventSource.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlClientEventSource.cs index 045b8c7eba..abee56fe5b 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlClientEventSource.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlClientEventSource.cs @@ -449,7 +449,7 @@ internal void TryScopeLeaveEvent(long scopeId) #region Execution Trace [NonEvent] - internal void TryBeginExecuteEvent(int objectId, object connectionId, string commandText, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "") + internal void TryBeginExecuteEvent(int objectId, Guid? connectionId, string commandText, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "") { if (Log.IsExecutionTraceEnabled()) { @@ -459,7 +459,7 @@ internal void TryBeginExecuteEvent(int objectId, object connectionId, string com } [NonEvent] - internal void TryEndExecuteEvent(int objectId, object connectionId, int compositeState, int sqlExceptionNumber, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "") + internal void TryEndExecuteEvent(int objectId, Guid? connectionId, int compositeState, int sqlExceptionNumber, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "") { if (Log.IsExecutionTraceEnabled()) {