sqlcmd - 连接到数据库引擎sqlcmd - Connect to the Database Engine
03/14/2017
本文内容
适用于:Applies to: SQL ServerSQL Server(所有支持的版本)SQL ServerSQL Server (all supported versions) Azure SQL 数据库Azure SQL DatabaseAzure SQL 数据库Azure SQL Database Azure SQL 托管实例Azure SQL Managed InstanceAzure SQL 托管实例Azure SQL Managed Instance Azure Synapse AnalyticsAzure Synapse AnalyticsAzure Synapse AnalyticsAzure Synapse Analytics 并行数据仓库Parallel Data Warehouse并行数据仓库Parallel Data Warehouse适用于:Applies to: SQL ServerSQL Server(所有支持的版本)SQL ServerSQL Server (all supported versions) Azure SQL 数据库Azure SQL DatabaseAzure SQL 数据库Azure SQL Database Azure SQL 托管实例Azure SQL Managed InstanceAzure SQL 托管实例Azure SQL Managed Instance Azure Synapse AnalyticsAzure Synapse AnalyticsAzure Synapse AnalyticsAzure Synapse Analytics 并行数据仓库Parallel Data Warehouse并行数据仓库Parallel Data Warehouse
SQL ServerSQL Server 支持客户端使用 TCP/IP 网络协议(默认)和命名管道协议进行通信。supports client communication with the TCP/IP network protocol (the default), and the named pipes protocol. 如果客户端正在连接到同一计算机上的数据库引擎Database Engine实例,则还可使用 Shared Memory 协议。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. sqlcmd 实用工具使用的协议按下列顺序确定:The protocol used by the sqlcmd utility is determined in the following order:
sqlcmd 使用为连接字符串中指定的协议,如下所述。sqlcmd uses the protocol specified as part of the connection string as described below.
如果连接字符串中未指定任何协议,则 sqlcmd 将使用连接到的别名中定义的协议。If no protocol is specified as part the connection string, sqlcmd will use the protocol defined as part of the alias that it is connecting to.
如果未通过其他方法指定协议, sqlcmd 将使用由 SQL ServerSQL Server 配置管理器中的协议顺序确定的网络协议。If the protocol is not specified in some other way, sqlcmd will use the network protocol determined by the protocol order in SQL ServerSQL Server Configuration Manager.
下面的示例显示连接到 1433 端口上默认的 数据库引擎Database Engine 实例以及假定侦听 1691 端口的 数据库引擎Database Engine 命名实例的各种方法。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. 其中一些示例使用环回适配器的 IP 地址 (127.0.0.1)。Some of these examples use the IP address of the loopback adapter (127.0.0.1). 请使用您的计算机网络接口卡的 IP 地址进行测试。Test using the IP address of your computer network interface card.
通过指定实例名连接到 数据库引擎Database Engine :Connect to the 数据库引擎Database Engine by specifying the instance name:
sqlcmd -S ComputerA
sqlcmd -S ComputerA\instanceB
通过指定 IP 地址连接到 数据库引擎Database Engine :Connect to the 数据库引擎Database Engine by specifying the IP address:
sqlcmd -S 127.0.0.1
sqlcmd -S 127.0.0.1\instanceB
通过指定 TCP\IP 端口号连接到 数据库引擎Database Engine :Connect to the 数据库引擎Database Engine by specifying the TCP\IP port number:
sqlcmd -S ComputerA,1433
sqlcmd -S ComputerA,1691
sqlcmd -S 127.0.0.1,1433
sqlcmd -S 127.0.0.1,1691
使用 TCP/IP 进行连接To connect using TCP/IP
使用以下常规语法进行连接:Connect using the following general syntax:
sqlcmd -S tcp:,
连接到默认实例:Connect to the default instance:
sqlcmd -S tcp:ComputerA,1433
sqlcmd -S tcp:127.0.0.1,1433
连接到命名实例:Connect to a named instance:
sqlcmd -S tcp:ComputerA,1691
sqlcmd -S tcp:127.0.0.1,1691
使用命名管道进行连接To connect using named pipes
使用下列常规语法之一进行连接:Connect using one of the following general syntax:
sqlcmd -S np:\\\
连接到默认实例:Connect to the default instance:
sqlcmd -S np:\\ComputerA\pipe\sql\query
sqlcmd -S np:\\127.0.0.1\pipe\sql\query
连接到命名实例:Connect to a named instance instance:
sqlcmd -S np:\\ComputerA\pipe\MSSQL$\sql\query
sqlcmd -S np:\\127.0.0.1\pipe\MSSQL$\sql\query
在服务器上从客户端使用共享内存(本地过程调用)进行连接To connect using shared memory (a local procedure call) from a client on the server
使用下列常规语法之一进行连接:Connect using one of the following general syntax:
sqlcmd -S lpc:
连接到默认实例:Connect to the default instance:
sqlcmd -S lpc:ComputerA
连接到命名实例:Connect to a named instance:
sqlcmd -S lpc:ComputerA\