Skip to content

Latest commit

 

History

History
120 lines (87 loc) · 5.87 KB

File metadata and controls

120 lines (87 loc) · 5.87 KB
title Creating a Valid Connection String Using Named Pipes | Microsoft Docs
ms.custom
ms.date 06/13/2017
ms.prod sql-server-2014
ms.reviewer
ms.technology configuration
ms.topic conceptual
helpviewer_keywords
connection strings [Database Engine], named pipes
pipes [SQL Server]
pipes [SQL Server], connecting to
aliases [SQL Server], named pipes
Named Pipes [SQL Server], connection strings
ms.assetid 90930ff2-143b-4651-8ae3-297103600e4f
author craigg-msft
ms.author craigg
manager craigg

Creating a Valid Connection String Using Named Pipes

Unless changed by the user, when the default instance of [!INCLUDEmsCoName] [!INCLUDEssNoVersion] listens on the named pipes protocol, it uses \\.\pipe\sql\query as the pipe name. The period indicates that the computer is the local computer, pipe indicates that the connection is a named pipe, and sql\query is the name of the pipe. To connect to the default pipe, the alias must have \\<computer_name>\pipe\sql\query as the pipe name. If [!INCLUDEssNoVersion] has been configured to listen on a different pipe, the pipe name must use that pipe. For instance, if [!INCLUDEssNoVersion] is using \\.\pipe\unit\app as the pipe, the alias must use \\<computer_name>\pipe\unit\app as the pipe name.

To create a valid pipe name, you must:

  • Specify an Alias Name.

  • Select Named Pipes as the Protocol.

  • Enter the Pipe Name. Alternatively, you can leave Pipe Name blank and [!INCLUDEssNoVersion] Configuration Manager will complete the appropriate pipe name after you specify the Protocol and Server

  • Specify a Server. For a named instance you can provide a server name and instance name.

At the time of connection, the [!INCLUDEssNoVersion] Native Client component reads the server, protocol, and pipe name values from the registry for the specified alias name, and creates a pipe name in the format np:\\<computer_name>\pipe\<pipename> or np:\\<IPAddress>\pipe\<pipename>.For a named instance, the default pipe name is \\<computer_name>\pipe\MSSQL$<instance_name>\sql\query.

Note

The [!INCLUDEmsCoName] Windows Firewall closes port 445 by default. Because [!INCLUDEmsCoName][!INCLUDEssNoVersion] communicates over port 445, you must reopen the port if [!INCLUDEssNoVersion] is configured to listen for incoming client connections using named pipes. For information on configuring a firewall, see "How to: Configure a Firewall for SQL Server Access" in [!INCLUDEssNoVersion] Books Online or review your firewall documentation.

Connecting to the Local Server

When connecting to [!INCLUDEssNoVersion] running on the same computer as the client, you can use (local)as the server name. Using (local) is not encouraged because it leads to ambiguity; however it can be useful when the client is known to be running on the intended computer. For instance, when creating an application for mobile disconnected users, such as a sales force, where [!INCLUDEssNoVersion] will run on laptop computers and store project data, a client connecting to (local) would always connect to the [!INCLUDEssNoVersion] running on the laptop. The word localhost or a period (.) can be used in place of (local).

Verifying Your Connection Protocol

The following query will return the protocol used for the current connection.

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

Examples

Connecting by server name to the default pipe:

Alias Name         <serveralias>  
Pipe Name          <blank>  
Protocol           Named Pipes  
Server             <servername>  
  

Connecting by IP Address to the default pipe:

Alias Name         <serveralias>  
Pipe Name          <leave blank>  
Protocol           Named Pipes  
Server             <IPAddress>  
  

Connecting by server name to a non-default pipe:

Alias Name         <serveralias>  
Pipe Name          \\<servername>\pipe\unit\app  
Protocol           Named Pipes  
Server             <servername>  
  

Connecting by server name to a named instance:

Alias Name         <serveralias>  
Pipe Name          \\<servername>\pipe\MSSQL$<instancename>\SQL\query  
Protocol           Named Pipes  
Server             <servername>  
  

Connecting to the local computer using localhost:

Alias Name         <serveralias>  
Pipe Name          <blank>  
Protocol           Named Pipes  
Server             localhost  
  

Connecting to the local computer using a period:

Alias Name         <serveralias>  
Pipe Name          <left blank>  
Protocol           Named Pipes  
Server             .  
  

Note

To specify the network protocol as a sqlcmd parameter, see "How to: Connect to the Database Engine Using sqlcmd.exe" in [!INCLUDEssNoVersion] Books Online.

See Also

Creating a Valid Connection String Using Shared Memory Protocol
Creating a Valid Connection String Using TCP IP
Choosing a Network Protocol