Use sqlcmd.exe to connect to the database

Source: Internet
Author: User

SQL Server supports communication between clients that use the TCP/IP network protocol (default), named pipe protocol, and via protocol. If the client is connected to a database engine instance on the same computer, you can also use the shared memory protocol. There are usually three methods to select the protocol. The protocols used by the sqlcmd utility are determined in the following order:

Sqlcmd uses the Protocol specified in the connection string (as described below ).

If no protocol is specified in the connection string, sqlcmd uses the protocol defined in its connected alias. To use a specific network protocol by creating an alias and configuring sqlcmd, see how to create a server alias for the client (SQL Server Configuration Manager ).

If the protocol is not specified in the preceding method, sqlcmd uses the network protocol determined by the protocol sequence in the SQL Server Configuration Manager. For more information, see how to configure the client to use a specific network protocol (SQL Server Configuration Manager ).

The following example shows how to connect to the default database engine instance on port 1433 and the database engine naming instance that listens on port 1691. Some examples use the IP address of the loop adapter (127.0.0.1 ). Use the IP address of your computer network interface card for testing.

Connect to the Database Engine by specifying the Instance name:

Sqlcmd-s compu.pdf

Sqlcmd-s computera \ instanceb

Connect to the Database Engine by specifying an IP Address:

Sqlcmd-s 127.0.0.1

Sqlcmd-s 127.0.0.1 \ instanceb

Connect to the Database Engine by specifying the TCP/IP Port:

Sqlcmd-s compuloud, 1433

Sqlcmd-s compuloud, 1691

Sqlcmd-s 127.0.0.1, 1433

Sqlcmd-s 127.0.0.1, 1691

Use TCP/IP for connection

Use the following general syntax to connect:

Sqlcmd-s TCP :,

Connect to the default instance:

Sqlcmd-s TCP: compuloud, 1433

Sqlcmd-s TCP: 127.0.0.1, 1433

Connect to the named instance:

Sqlcmd-s TCP: compuloud, 1691

Sqlcmd-s TCP: 127.0.0.1, 1691

Connect using a named pipe

Use one of the following general syntaxes to connect:

Sqlcmd-s NP :\\\

Connect to the default instance:

Sqlcmd-s NP: \ compuloud \ PIPE \ SQL \ QUERY

Sqlcmd-s NP: \ 127.0.0.1 \ PIPE \ SQL \ QUERY

Connect to the named instance:

Sqlcmd-s NP: \ compuloud \ PIPE \ MSSQL $ \ SQL \ QUERY

Sqlcmd-s NP: \ 127.0.0.1 \ PIPE \ MSSQL $ \ SQL \ QUERY

Connect from the client using shared memory (called locally) on the server

Use one of the following general syntaxes to connect:

Sqlcmd-s LPC:

Connect to the default instance:

Sqlcmd-s LPC: compu.pdf

Connect to the named instance:

Sqlcmd-s LPC: computera \ Connect using

Use one of the following general syntaxes to connect:

Sqlcmd-s :,,

Connect to the default instance:

Sqlcmd-s via: compuloud, 1433,0

Connect to the named instance:

Sqlcmd-s via: compuloud, 1691,0

Note:

If the full connection information is not provided, SQL Server Browser provides the connection information of the default port and NIC (if the browser is running ).

Http://www.51edu.com/it/yingjian/wlaq/jiaocheng/2791639.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.