Create a valid connection string using TCP/IP
Applies to:
SQL Server - Windows only
To create a valid connection string using TCP/IP, you must:
Specify an Alias Name.
For the Server, enter either a server name to which you can connect using the ping utility, or an IP address to which you can connect using the ping utility. For a named instance, append the instance name.
Specify TCP/IP for the Protocol.
Optionally, enter a port number for the Port No. The default is
1433
, which is the port number of the default instance of the Database Engine on a server. To connect to a named instance or a default instance that isn't listening on port 1433, you must provide the port number, or start the SQL Server Browser service. For information on configuring the SQL Server Browser service, see SQL Server Browser Service.
At the time of connection, the SQL Server Native Client component reads the server, protocol, and port values from the registry for the specified alias name, and creates a connection string in the format tcp:<servername>[\<instancename>],<port>
or tcp:<IPAddress>[\<instancename>],<port>
.
Note
The Windows Firewall closes port 1433 by default. Because SQL Server communicates over port 1433, you must reopen the port if SQL Server is configured to listen for incoming client connections using TCP/IP. For information on configuring a firewall, see "How to: Configure a Firewall for SQL Server Access" in SQL Server Books Online or review your firewall documentation.
SQL Server and SQL Server Native Client fully support both Internet Protocol version 4 (IPv4) and Internet Protocol version 6 (IPv6). SQL Server Configuration Manager accepts both IPv4 and IPv6 formats for IP addresses. For information on IPv6, see "Connecting Using IPv6" in SQL Server Books Online.
Connect to the local server
When connecting to SQL Server running on the same computer as the client, you can use (local)
as the server name. This value isn't encouraged as 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, where SQL Server runs on laptop computers and stores project data, a client connecting to (local)
would always connect to the SQL Server running on the laptop. The word localhost
or a period (.) can be used in place of (local)
.
Verify your connection protocol
The following query returns the protocol used for the current connection.
SELECT net_transport
FROM sys.dm_exec_connections
WHERE session_id = @@SPID;
Examples
Connecting by server name:
Setting | Value |
---|---|
Alias Name | <serveralias> |
Port No | <blank> |
Protocol | TCP/IP |
Server | <servername> |
Connecting by server name to a named instance:
Setting | Value |
---|---|
Alias Name | <serveralias> |
Port No | <blank> |
Protocol | TCP/IP |
Server | <servername>\<instancename> |
Connecting by server name to a specified port:
Setting | Value |
---|---|
Alias Name | <serveralias> |
Port No | <port> |
Protocol | TCP/IP |
Server | <servername> |
Connecting by IP address:
Setting | Value |
---|---|
Alias Name | <serveralias> |
Port No | <blank> |
Protocol | TCP/IP |
Server | <IPAddress> |
Connecting by IP address to a named instance:
Setting | Value |
---|---|
Alias Name | <serveralias> |
Port No | <blank> |
Protocol | TCP/IP |
Server | <IPAddress>\<instancename> |
Connecting by IP address to a specified port:
Setting | Value |
---|---|
Alias Name | <serveralias> |
Port No | <port number> |
Protocol | TCP/IP |
Server | <IPAddress> |
Connecting to the local computer using (local)
:
Setting | Value |
---|---|
Alias Name | <serveralias> |
Port No | <blank> |
Protocol | TCP/IP |
Server | (local) |
Connecting to the local computer using localhost
:
Setting | Value |
---|---|
Alias Name | <serveralias> |
Port No | <blank> |
Protocol | TCP/IP |
Server | localhost |
Connecting to a named instance on the local computer localhost
:
Setting | Value |
---|---|
Alias Name | <serveralias> |
Port No | <blank> |
Protocol | TCP/IP |
Server | localhost\<instancename> |
Connecting to the local computer using a period:
Setting | Value |
---|---|
Alias Name | <serveralias> |
Port No | <blank> |
Protocol | TCP/IP |
Server | . |
Connecting to a named instance on the local computer using a period:
Setting | Value |
---|---|
Alias Name | <serveralias> |
Port No | <blank> |
Protocol | TCP/IP |
Server | .\<instancename> |
Note
For information on specifying the network protocol as a sqlcmd parameter, see sqlcmd - Connect to the database engine.