Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Named pipes (np:) don't support named instances in Managed SNI #2113

Closed
cheenamalhotra opened this issue Aug 4, 2023 · 1 comment · Fixed by #2142
Closed

Named pipes (np:) don't support named instances in Managed SNI #2113

cheenamalhotra opened this issue Aug 4, 2023 · 1 comment · Fixed by #2142
Labels
Area\Managed SNI Issues that are targeted to the Managed SNI codebase. 🐛 Bug! Issues that are bugs in the drivers we maintain.

Comments

@cheenamalhotra
Copy link
Member

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

@cheenamalhotra cheenamalhotra added Area\Managed SNI Issues that are targeted to the Managed SNI codebase. 🐛 Bug! Issues that are bugs in the drivers we maintain. labels Aug 4, 2023
@JRahnama
Copy link
Contributor

JRahnama commented Aug 7, 2023

thnaks @cheenamalhotra. We will look into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area\Managed SNI Issues that are targeted to the Managed SNI codebase. 🐛 Bug! Issues that are bugs in the drivers we maintain.
Projects
Development

Successfully merging a pull request may close this issue.

2 participants