Skip to content

Commit 0352a50

Browse files
authored
3 Small Changes (#2594)
* * Port sqlclientx datasource changes * Remove link to missing nuget.config file * Remove root namespaces from sqlclient csproj files * Test to see if namespace changes are breaking the pr build * Reinstate removing the root namespace and fix resource filename generation
1 parent f55c5a2 commit 0352a50

File tree

4 files changed

+33
-27
lines changed

4 files changed

+33
-27
lines changed

src/Microsoft.Data.SqlClient.sln

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ EndProject
196196
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{4F3CD363-B1E6-4D6D-9466-97D78A56BE45}"
197197
ProjectSection(SolutionItems) = preProject
198198
Directory.Build.props = Directory.Build.props
199-
NuGet.config = NuGet.config
200199
EndProjectSection
201200
EndProject
202201
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.SqlServer.Server", "Microsoft.SqlServer.Server\Microsoft.SqlServer.Server.csproj", "{A314812A-7820-4565-A2A8-ABBE391C11E4}"

src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<Product>Core $(BaseProduct)</Product>
1919
<EnableTrimAnalyzer Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">true</EnableTrimAnalyzer>
2020
<NoWarn>$(NoWarn);IL2026;IL2057;IL2072;IL2075</NoWarn>
21+
<RootNamespace />
2122
</PropertyGroup>
2223
<PropertyGroup>
2324
<TargetFrameworkMonikerAssemblyAttributesPath>$([System.IO.Path]::Combine('$(IntermediateOutputPath)','$(TargetFrameworkMoniker).AssemblyAttributes$(DefaultLanguageSourceExtension)'))</TargetFrameworkMonikerAssemblyAttributesPath>
@@ -932,6 +933,7 @@
932933
</EmbeddedResource>
933934
<EmbeddedResource Include="$(CommonSourceRoot)Resources\$(ResxFileName).*.resx">
934935
<Link>Resources\%(RecursiveDir)%(Filename)%(Extension)</Link>
936+
<LogicalName>Microsoft.Data.SqlClient.Resources.%(Filename).resources</LogicalName>
935937
</EmbeddedResource>
936938
<EmbeddedResource Include="Resources\Microsoft.Data.SqlClient.SqlMetaData.xml">
937939
<LogicalName>Microsoft.Data.SqlClient.SqlMetaData.xml</LogicalName>

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIProxy.cs

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ internal static SNIHandle CreateConnectionHandle(
197197
}
198198

199199
SNIHandle sniHandle = null;
200-
switch (details._connectionProtocol)
200+
switch (details.ResolvedProtocol)
201201
{
202202
case DataSource.Protocol.Admin:
203203
case DataSource.Protocol.None: // default to using tcp if no protocol is provided
@@ -209,7 +209,7 @@ internal static SNIHandle CreateConnectionHandle(
209209
sniHandle = CreateNpHandle(details, timeout, parallel, tlsFirst, hostNameInCertificate, serverCertificateFilename);
210210
break;
211211
default:
212-
Debug.Fail($"Unexpected connection protocol: {details._connectionProtocol}");
212+
Debug.Fail($"Unexpected connection protocol: {details.ResolvedProtocol}");
213213
break;
214214
}
215215

@@ -245,11 +245,11 @@ private static byte[][] GetSqlServerSPNs(DataSource dataSource, string serverSPN
245245
}
246246
else if (!string.IsNullOrWhiteSpace(dataSource.InstanceName))
247247
{
248-
postfix = dataSource._connectionProtocol == DataSource.Protocol.TCP ? dataSource.ResolvedPort.ToString() : dataSource.InstanceName;
248+
postfix = dataSource.ResolvedProtocol == DataSource.Protocol.TCP ? dataSource.ResolvedPort.ToString() : dataSource.InstanceName;
249249
}
250250

251251
SqlClientEventSource.Log.TryTraceEvent("SNIProxy.GetSqlServerSPN | Info | ServerName {0}, InstanceName {1}, Port {2}, postfix {3}", dataSource?.ServerName, dataSource?.InstanceName, dataSource?.Port, postfix);
252-
return GetSqlServerSPNs(hostName, postfix, dataSource._connectionProtocol);
252+
return GetSqlServerSPNs(hostName, postfix, dataSource.ResolvedProtocol);
253253
}
254254

255255
private static byte[][] GetSqlServerSPNs(string hostNameOrAddress, string portOrInstanceName, DataSource.Protocol protocol)
@@ -327,7 +327,7 @@ private static SNITCPHandle CreateTcpHandle(
327327
}
328328

329329
int port = -1;
330-
bool isAdminConnection = details._connectionProtocol == DataSource.Protocol.Admin;
330+
bool isAdminConnection = details.ResolvedProtocol == DataSource.Protocol.Admin;
331331
if (details.IsSsrpRequired)
332332
{
333333
try
@@ -440,8 +440,6 @@ internal class DataSource
440440

441441
internal enum Protocol { TCP, NP, None, Admin };
442442

443-
internal Protocol _connectionProtocol = Protocol.None;
444-
445443
/// <summary>
446444
/// Provides the HostName of the server to connect to for TCP protocol.
447445
/// This information is also used for finding the SPN of SqlServer
@@ -473,6 +471,12 @@ internal enum Protocol { TCP, NP, None, Admin };
473471
/// </summary>
474472
internal string PipeHostName { get; private set; }
475473

474+
/// <summary>
475+
/// Gets or sets the protocol that was resolved from the connection string. If this is
476+
/// <see cref="Protocol.None"/>, the protocol could not reliably be determined.
477+
/// </summary>
478+
internal Protocol ResolvedProtocol { get; private set; }
479+
476480
private string _workingDataSource;
477481
private string _dataSourceAfterTrimmingProtocol;
478482

@@ -489,16 +493,16 @@ private DataSource(string dataSource)
489493

490494
PopulateProtocol();
491495

492-
_dataSourceAfterTrimmingProtocol = (firstIndexOfColon > -1) && _connectionProtocol != Protocol.None
496+
_dataSourceAfterTrimmingProtocol = (firstIndexOfColon > -1) && ResolvedProtocol != Protocol.None
493497
? _workingDataSource.Substring(firstIndexOfColon + 1).Trim() : _workingDataSource;
494498

495499
if (_dataSourceAfterTrimmingProtocol.Contains(Slash)) // Pipe paths only allow back slashes
496500
{
497-
if (_connectionProtocol == Protocol.None)
501+
if (ResolvedProtocol == Protocol.None)
498502
ReportSNIError(SNIProviders.INVALID_PROV);
499-
else if (_connectionProtocol == Protocol.NP)
503+
else if (ResolvedProtocol == Protocol.NP)
500504
ReportSNIError(SNIProviders.NP_PROV);
501-
else if (_connectionProtocol == Protocol.TCP)
505+
else if (ResolvedProtocol == Protocol.TCP)
502506
ReportSNIError(SNIProviders.TCP_PROV);
503507
}
504508
}
@@ -509,25 +513,25 @@ private void PopulateProtocol()
509513

510514
if (splitByColon.Length <= 1)
511515
{
512-
_connectionProtocol = Protocol.None;
516+
ResolvedProtocol = Protocol.None;
513517
}
514518
else
515519
{
516520
// We trim before switching because " tcp : server , 1433 " is a valid data source
517521
switch (splitByColon[0].Trim())
518522
{
519523
case TdsEnums.TCP:
520-
_connectionProtocol = Protocol.TCP;
524+
ResolvedProtocol = Protocol.TCP;
521525
break;
522526
case TdsEnums.NP:
523-
_connectionProtocol = Protocol.NP;
527+
ResolvedProtocol = Protocol.NP;
524528
break;
525529
case TdsEnums.ADMIN:
526-
_connectionProtocol = Protocol.Admin;
530+
ResolvedProtocol = Protocol.Admin;
527531
break;
528532
default:
529533
// None of the supported protocols were found. This may be a IPv6 address
530-
_connectionProtocol = Protocol.None;
534+
ResolvedProtocol = Protocol.None;
531535
break;
532536
}
533537
}
@@ -611,7 +615,7 @@ private void InferLocalServerName()
611615
// If Server name is empty or localhost, then use "localhost"
612616
if (string.IsNullOrEmpty(ServerName) || IsLocalHost(ServerName) ||
613617
(Environment.MachineName.Equals(ServerName, StringComparison.CurrentCultureIgnoreCase) &&
614-
_connectionProtocol == Protocol.Admin))
618+
ResolvedProtocol == Protocol.Admin))
615619
{
616620
// For DAC use "localhost" instead of the server name.
617621
ServerName = DefaultHostName;
@@ -643,11 +647,11 @@ private bool InferConnectionDetails()
643647
}
644648

645649
// For Tcp and Only Tcp are parameters allowed.
646-
if (_connectionProtocol == Protocol.None)
650+
if (ResolvedProtocol == Protocol.None)
647651
{
648-
_connectionProtocol = Protocol.TCP;
652+
ResolvedProtocol = Protocol.TCP;
649653
}
650-
else if (_connectionProtocol != Protocol.TCP)
654+
else if (ResolvedProtocol != Protocol.TCP)
651655
{
652656
// Parameter has been specified for non-TCP protocol. This is not allowed.
653657
ReportSNIError(SNIProviders.INVALID_PROV);
@@ -705,15 +709,15 @@ private void ReportSNIError(SNIProviders provider)
705709
private bool InferNamedPipesInformation()
706710
{
707711
// If we have a datasource beginning with a pipe or we have already determined that the protocol is Named Pipe
708-
if (_dataSourceAfterTrimmingProtocol.StartsWith(PipeBeginning, StringComparison.Ordinal) || _connectionProtocol == Protocol.NP)
712+
if (_dataSourceAfterTrimmingProtocol.StartsWith(PipeBeginning, StringComparison.Ordinal) || ResolvedProtocol == Protocol.NP)
709713
{
710714
// If the data source starts with "np:servername"
711715
if (!_dataSourceAfterTrimmingProtocol.Contains(PipeBeginning))
712716
{
713717
// Assuming that user did not change default NamedPipe name, if the datasource is in the format servername\instance,
714718
// separate servername and instance and prepend instance with MSSQL$ and append default pipe path
715719
// https://learn.microsoft.com/en-us/sql/tools/configuration-manager/named-pipes-properties?view=sql-server-ver16
716-
if (_dataSourceAfterTrimmingProtocol.Contains(PathSeparator) && _connectionProtocol == Protocol.NP)
720+
if (_dataSourceAfterTrimmingProtocol.Contains(PathSeparator) && ResolvedProtocol == Protocol.NP)
717721
{
718722
string[] tokensByBackSlash = _dataSourceAfterTrimmingProtocol.Split(BackSlashCharacter);
719723
if (tokensByBackSlash.Length == 2)
@@ -800,11 +804,11 @@ private bool InferNamedPipesInformation()
800804
}
801805

802806
// DataSource is something like "\\pipename"
803-
if (_connectionProtocol == Protocol.None)
807+
if (ResolvedProtocol == Protocol.None)
804808
{
805-
_connectionProtocol = Protocol.NP;
809+
ResolvedProtocol = Protocol.NP;
806810
}
807-
else if (_connectionProtocol != Protocol.NP)
811+
else if (ResolvedProtocol != Protocol.NP)
808812
{
809813
// In case the path began with a "\\" and protocol was not Named Pipes
810814
ReportSNIError(SNIProviders.NP_PROV);

src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.Net.Sdk">
22
<PropertyGroup>
33
<ProjectGuid>{407890AC-9876-4FEF-A6F1-F36A876BAADE}</ProjectGuid>
4-
<RootNamespace>Microsoft.Data.SqlClient</RootNamespace>
4+
<RootNamespace></RootNamespace>
55
<TargetFramework>net462</TargetFramework>
66
<EnableLocalAppContext>true</EnableLocalAppContext>
77
<AssemblyName>Microsoft.Data.SqlClient</AssemblyName>
@@ -725,6 +725,7 @@
725725
</EmbeddedResource>
726726
<EmbeddedResource Include="$(CommonSourceRoot)Resources\$(ResxFileName).*.resx">
727727
<Link>Resources\%(RecursiveDir)%(Filename)%(Extension)</Link>
728+
<LogicalName>Microsoft.Data.SqlClient.Resources.%(Filename).resources</LogicalName>
728729
</EmbeddedResource>
729730
<EmbeddedResource Include="Resources\Microsoft.Data.SqlClient.SqlMetaData.xml">
730731
<LogicalName>Microsoft.Data.SqlClient.SqlMetaData.xml</LogicalName>

0 commit comments

Comments
 (0)