--- title: Connect to SQL Server with sqlcmd description: "Learn how to select which protocol sqlcmd uses to communicate with SQL Server. The choices are: TCP/IP, named pipes, and shared memory." author: dlevy-msft ms.author: dlevy ms.reviewer: maghan, randolphwest, mathoma ms.date: 11/25/2024 ms.service: sql ms.subservice: tools-other ms.topic: how-to ms.collection: - data-tools ms.custom: - ignite-2024 helpviewer_keywords: - "sqlcmd utility, Database Engine connections" - "Named Pipes [SQL Server], sqlcmd utility" - "TCP/IP [SQL Server], client protocols" - "network protocols [SQL Server], sqlcmd utility" - "protocols [SQL Server], sqlcmd utility" - "VIA" - "client protocols [SQL Server]" monikerRange: ">=aps-pdw-2016 || =azuresqldb-current || =azure-sqldw-latest || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =fabric" --- # Connect to SQL Server with sqlcmd [!INCLUDE [SQL Server Azure SQL Database Azure SQL Managed Instance Azure Synapse Analytics PDW FabricSQLDB](../../includes/applies-to-version/sql-asdb-asdbmi-asa-pdw-fabricsqldb.md)] This article describes how to connect to the SQL Server database engine by using the [sqlcmd utility](sqlcmd-utility.md). ## Overview [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] supports client communication with the TCP/IP network protocol (the default), and the named pipes protocol. The shared memory protocol is also available if the client is connecting to an instance of the Database Engine on the same computer. There are three common methods of selecting the protocol. The protocol used by the **sqlcmd** utility is determined in the following order: - **sqlcmd** uses the protocol specified as part of the connection string, as described later in this article. - If no protocol is specified as part the connection string, **sqlcmd** uses the protocol defined as part of the alias that's connected. To configure **sqlcmd** to use a specific network protocol by creating an alias, see [Create or delete a server alias for use by a client](../../database-engine/configure-windows/create-or-delete-a-server-alias-for-use-by-a-client.md). - If the protocol isn't specified in some other way, **sqlcmd** uses the network protocol determined by the protocol order in [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] Configuration Manager. The following examples show various ways of connecting to the default instance of Database Engine on port 1433, and named instances of Database Engine presumed to be listening on port 1691. Some of these examples use the IP address of the loopback adapter (127.0.0.1). Test using the IP address of your computer network interface card. Connect to the Database Engine by specifying the instance name: ```console sqlcmd -S ComputerA sqlcmd -S ComputerA\instanceB ``` Connect to the Database Engine by specifying the IP address: ```console sqlcmd -S 127.0.0.1 sqlcmd -S 127.0.0.1\instanceB ``` Connect to the Database Engine by specifying the TCP\IP port number: ```console sqlcmd -S ComputerA,1433 sqlcmd -S ComputerA,1691 sqlcmd -S 127.0.0.1,1433 sqlcmd -S 127.0.0.1,1691 ``` ## Connect using TCP/IP - Connect using the following general syntax: ```console sqlcmd -S tcp:, ``` - Connect to the default instance: ```console sqlcmd -S tcp:ComputerA,1433 sqlcmd -S tcp:127.0.0.1,1433 ``` - Connect to a named instance: ```console sqlcmd -S tcp:ComputerA,1691 sqlcmd -S tcp:127.0.0.1,1691 ``` ## Connect using named pipes - Connect using one of the following general syntaxes: ```console sqlcmd -S np:\\\ ``` - Connect to the default instance: ```console sqlcmd -S np:\\ComputerA\pipe\sql\query sqlcmd -S np:\\127.0.0.1\pipe\sql\query ``` - Connect to a named instance: ```console sqlcmd -S np:\\ComputerA\pipe\MSSQL$\sql\query sqlcmd -S np:\\127.0.0.1\pipe\MSSQL$\sql\query ``` ## Connect using shared memory (a local procedure call) from a client on the server - Connect using one of the following general syntaxes: ```console sqlcmd -S lpc: ``` - Connect to the default instance: ```console sqlcmd -S lpc:ComputerA ``` - Connect to a named instance: ```console sqlcmd -S lpc:ComputerA\ ``` ## Related content - [sqlcmd utility](sqlcmd-utility.md)