Click to Rate and Give Feedback
MSDN
MSDN Library
SQL Server
SQL Server 2008
Database Engine
Operations
Administration
 How to: Connect to the Database Eng...
Other versions are also available for the following:
SQL Server 2008 Books Online
How to: Connect to the Database Engine Using sqlcmd.exe

SQL Server supports client communication with the TCP/IP network protocol (the default), the named pipes protocol, and the VIA 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:

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:

sqlcmd -S ComputerA
sqlcmd -S ComputerA\instanceB

Connect to the Database Engine by specifying the 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 number:

sqlcmd -S ComputerA,1433
sqlcmd -S ComputerA,1691
sqlcmd -S 127.0.0.1,1433
sqlcmd -S 127.0.0.1,1691
  • Connect using the following general syntax:

    sqlcmd -S tcp:<computer name>,<port number>
  • 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
  • Connect using one of the following general syntax:

    sqlcmd -S np:\\<computer name>\<pipe name>
  • 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$<instancename>\sql\query
    sqlcmd -S np:\\127.0.0.1\pipe\MSSQL$<instancename>\sql\query
  • Connect using one of the following general syntax:

    sqlcmd -S lpc:<computer name>
  • Connect to the default instance:

    sqlcmd -S lpc:ComputerA
  • Connect to a named instance:

    sqlcmd -S lpc:ComputerA\<instancename>
  • Connect using one of the following general syntax:

    sqlcmd -S via:<computer name>,<port number>,<NIC number>
  • Connect to the default instance:

    sqlcmd -S via:ComputerA,1433,0
  • Connect to a named instance:

    sqlcmd -S via:ComputerA,1691,0
Note:
If complete connection information is not provided, SQL Server Browser will provide connection information for the default port and NIC, if it is running.

Note:
This topic only discusses the connectivity options for the sqlcmd utility. There are many additional parameters available for the sqlcmd utility. For more information, see sqlcmd Utility.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker