Connecting over Named Pipes protocol

Configuring named pipes

To configure the Named Pipes protocol on the SQL Server database server (using SQL Server 2019 on Windows Server 2019 64-bit as an example):

  1. Open SQL Server Configuration Manager from the Windows Start menu > SQL Server 2019 > SQL Server 2019 Configuration Manager.

  2. Select the instance to be connected under SQL Server Network Configuration (such as Protocols for MSSQLSERVER), and then double click on Named Pipes on the right-hand side. In the dialog box that pops up, write down the Pipe Name which is by default '\\.\pipe\sql\query', or double click on Pipe Name to modify the pipe name and then write down the new pipe name. The pipe name will be used for connection later.

  3. Make sure the status of Named Pipes is set to "Enabled".

For more about Named Pipes configuration, refer to Named Pipes Properties.

Connecting over Named Pipes

To configure the SQL Server database connection over the Named Pipes protocol:

Specify the Server host field according to the following connection strings:

Data Source=\\.\pipe\sql\query;Initial Catalog=MyDB;User ID=sa;Password=mypwd;
Data Source=\\.\pipe\MSSQL$MSSQLSERVER01\sql\query;Initial Catalog=SnapTest;User ID=sa;Password=mypwd;
Data Source=np:\\172.0.0.1\pipe\sql\query;Initial Catalog=SnapTest;User ID=sa;Password=mypwd;
Data Source=np:MyMachineName;Initial Catalog=MyDB;User ID=sa;Password=mypwd;

Tips:

You can check which protocol is currently used by executing the following SQL statement:

SELECT net_transport FROM sys.dm_exec_connections WHERE session_id =@@SPID;

You can specify the protocol in the server host by adding the following prefix before the server name: np:, tcp:, or lcp:.

If you add the "tcp:" prefix to the server host, then TCP/IP protocol will be used even though it connects with a local database.

If the server host is entered with an IP address, even if the "lcp:" prefix is added, it will still connect to the database over TCP/IP.

If you want to connect to the specified instance, you can add "\"+"instance name" to the server host, for example ".\MSSQLSERVER01".