Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ internal static class IpAddressPreferenceUtilities

static IpAddressPreferenceUtilities()
{
foreach (SqlConnectionIPAddressPreference item in Enum.GetValues(typeof(SqlConnectionIPAddressPreference)))
foreach (SqlConnectionIPAddressPreference item in new[]
Comment thread
charlesroddie marked this conversation as resolved.
Resolved
{
SqlConnectionIPAddressPreference.IPv4First,
SqlConnectionIPAddressPreference.IPv6First,
SqlConnectionIPAddressPreference.UsePlatformDefault
})
{
s_preferenceNames.Add(item.ToString(), item);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Data;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Security;
using System.Text;
Expand Down Expand Up @@ -147,15 +148,8 @@ private static DataTable ParseServerEnumString(string serverInstances)
version = instance2.Substring(s_versionLength);
}

string query = "ServerName='" + serverName + "'";

if (!string.IsNullOrEmpty(instanceName))
{ // SQL BU DT 20006584: only append instanceName if present.
query += " AND InstanceName='" + instanceName + "'";
}

// SNI returns dupes - do not add them. SQL BU DT 290323
if (dataTable.Select(query).Length == 0)
if (!ContainsInstance(dataTable, serverName, instanceName))
Comment thread
charlesroddie marked this conversation as resolved.
Resolved
Comment thread
charlesroddie marked this conversation as resolved.
Resolved
{
DataRow dataRow = dataTable.NewRow();
dataRow[0] = serverName;
Expand All @@ -171,5 +165,28 @@ private static DataTable ParseServerEnumString(string serverInstances)
}
return dataTable.SetColumnsReadOnly();
}

private static bool ContainsInstance(DataTable dataTable, string serverName, string instanceName)
{
CompareInfo compareInfo = dataTable.Locale.CompareInfo;

foreach (DataRow row in dataTable.Rows)
{
if (EqualsInTable(compareInfo, row[ServerNameCol] as string, serverName) &&
// SQL BU DT 20006584: only match instanceName if present.
(string.IsNullOrEmpty(instanceName) || EqualsInTable(compareInfo, row[InstanceNameCol] as string, instanceName)))
{
return true;
}
}
return false;
}
Comment thread
charlesroddie marked this conversation as resolved.
Resolved

// Matches DataTable's string equality for a case-insensitive table.
private static bool EqualsInTable(CompareInfo compareInfo, string s1, string s2) =>
compareInfo.Compare(
s1?.TrimEnd(' ', '\u3000'),
s2?.TrimEnd(' ', '\u3000'),
CompareOptions.IgnoreCase | CompareOptions.IgnoreKanaType | CompareOptions.IgnoreWidth) == 0;
Comment thread
charlesroddie marked this conversation as resolved.
Resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private bool LoadUserInstanceDll()
}

// Set the delegate the invoke.
localDBStartInstanceFunc = (LocalDBStartInstance)Marshal.GetDelegateForFunctionPointer(_startInstanceHandle, typeof(LocalDBStartInstance));
localDBStartInstanceFunc = Marshal.GetDelegateForFunctionPointer<LocalDBStartInstance>(_startInstanceHandle);

if (localDBStartInstanceFunc == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Data;
using System.Data.Common;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Text;
Expand Down Expand Up @@ -371,6 +372,10 @@ private string GetParameterName(string neededCollectionName, int neededRestricti
return result;
}

#if NET
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2072",
Justification = "Schema collection columns are built-in CLR types; DataColumn only reflects over INullable column types.")]
#endif
private async ValueTask<DataTable> ExecuteCommandAsync(DataRow requestedCollectionRow, string[] restrictions, DbConnection connection, bool isAsync, CancellationToken cancellationToken)
{
Debug.Assert(requestedCollectionRow is not null);
Expand Down