-
Notifications
You must be signed in to change notification settings - Fork 322
Closed
Labels
Area\Managed SNIIssues that are targeted to the Managed SNI codebase.Issues that are targeted to the Managed SNI codebase.
Description
Describe the bug
Native SNI supports server name in below format, while Managed SNI fails to work with it and throws error.
Server=np:localhost\\MSSQLSERVER02;
Exception message: Microsoft.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
---> System.IO.IOException: The network name cannot be found.
at System.IO.Pipes.NamedPipeClientStream.TryConnect(Int32 timeout, CancellationToken cancellationToken)
at System.IO.Pipes.NamedPipeClientStream.ConnectInternal(Int32 timeout, CancellationToken cancellationToken, Int32 startTime)
at Microsoft.Data.SqlClient.SNI.SNINpHandle..ctor(String serverName, String pipeName, Int64 timerExpire, Boolean tlsFirst)
at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
To reproduce
Console app targeting .NET 6/7
public static async Task Main()
{
// When switch is commented out, connection is successful!
AppContext.SetSwitch("Switch.Microsoft.Data.SqlClient.UseManagedNetworkingOnWindows", true);
using (SqlConnection conn = new("Server=np:localhost\\MSSQLSERVER02; Integrated Security=true; Pooling=false;"))
{
try
{
await conn.OpenAsync(); // conn.Open();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}Expected behavior
Connect as Native SNI
Further technical details
Microsoft.Data.SqlClient version: 5.1.1, main
.NET target: .NET 6/7
Microsoft SQL Server 2022 (RTM-GDR) (KB5021522) - 16.0.1050.5 (X64)
Jan 23 2023 17:02:42
Copyright (C) 2022 Microsoft Corporation
Developer Edition (64-bit) on Windows 10 Pro 10.0 (Build 22621: ) (Hypervisor)
Operating system: Windows 11
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Area\Managed SNIIssues that are targeted to the Managed SNI codebase.Issues that are targeted to the Managed SNI codebase.