Događaji
M03 31 23 - M04 2 23
Najveći događaj učenja jezika SQL, platforme Fabric i platforme Power BI. 31. mart - 2. april Koristite kod FABINSIDER da uštedite 400 dolara.
Registrirajte se danasOvaj preglednik više nije podržan.
Nadogradite na Microsoft Edge da iskoristite najnovije osobine, sigurnosna ažuriranja i tehničku podršku.
This article provides a high level overview for connecting to the SQL Server Database Engine, used by the following products and services:
You connect to the Database Engine using a client tool or client library. Client tools run in a graphical user interface (GUI), or a command-line interface (CLI).
The following table describes some of the more common client tools.
Client tool | Type | Operating system |
---|---|---|
SQL Server Management Studio (SSMS) | GUI | Windows |
MSSQL extension for Visual Studio Code | GUI | Windows, macOS, Linux |
sqlcmd | CLI | Windows, macOS, Linux |
bcp | CLI | Windows, macOS, Linux |
Bilješka
Client tools include at least one client library. For more information about connecting with a client library, see Connection modules for Microsoft SQL Database.
When you connect to the Database Engine, you must provide an instance name (that is, the server or instance where the Database Engine is installed), a network protocol, and a connection port, in the following format:
[<protocol>:]<instance>[,<port>]
The protocol and port are optional because they have default values. Depending on the client tool and client library, they can be skipped.
Bilješka
If you use a custom TCP port for connecting to the Database Engine, you must separate it with a comma (,
), because the colon (:
) is used to specify the protocol.
Setting | Values | Default | Details |
---|---|---|---|
Protocol | tcp (TCP/IP), np (named pipes), or lpc (shared memory). |
np is the default when connecting to SQL Server.tcp is the default when connecting to Azure SQL services. |
Protocol is optional, and is frequently excluded when connecting to SQL Server on the same computer as the client tool. For more information, see Network protocol considerations in the next section. |
Instance | The name of the server or instance. For example, MyServer or MyServer\MyInstance . |
localhost |
If the Database Engine is located on the same computer as the client tool, you might be able to connect using localhost , 127.0.0.1 , or even . (a single period).If you're connecting to a named instance, you must specify the server name and the instance name, separated by a slash. For example, MyServer\MyInstance . A named instance on the local machine is specified by .\MyInstance . SQL Server Express uses MyServer\SQLEXPRESS . |
Port | Any TCP port. | 1433 |
The default TCP port for connecting to the default instance of SQL Server is 1433 . However, your infrastructure team might configure custom ports.SQL Server on Windows, including SQL Server Express edition, can be configured as a named instance and might also have a custom port. For connecting to Azure SQL services, see the Connect to Azure SQL section. For more information about custom ports with SQL Server, see SQL Server Configuration Manager. |
For SQL Server on Windows, when you connect to an instance on the same machine as the client tool, and depending on which edition is installed, the default protocol can be configured with multiple protocols, including named pipes (np
), TCP/IP (tcp
), and shared memory (lpc
). Use the shared memory protocol for troubleshooting when you suspect the other protocols are configured incorrectly.
If you connect to SQL Server over a TCP/IP network, make sure that TCP/IP is enabled on the server as well. TCP/IP might be disabled by default on installations of SQL Server. For more information, see Default SQL Server Network Protocol Configuration.
Connections to Azure SQL services, SQL Server on Linux, and SQL Server in containers, all use TCP/IP.
For both Azure SQL Database and Azure SQL Managed Instance, see Connect and query articles.
This section provides information on connecting to Azure SQL services.
To quickly connect to and query an Azure SQL Database from the Azure portal, use the Azure portal Query editor for Azure SQL Database.
For external connections, be aware of the secure-by-default Azure SQL Database database-level firewall.
Examples for application connections are available:
This section provides information on connecting to SQL Server.
You can connect to the local machine using named pipes (np
), shared memory (lpc
), or TCP/IP (tcp
). Shared memory is the fastest, because it doesn't use the network interface.
Bilješka
If you use an IP address for your instance name and don't specify tcp
, the protocol defaults to np
(named pipes) if it's a configured protocol.
A named instance has a dynamically assigned TCP port. If you want to connect to a named instance, the SQL Server Browser service must be running on the server.
If you're connecting to a server configured with default settings, use one of the following options:
localhost
127.0.0.1
.
(a single period)If you're connecting to a custom TCP port, such as 51433
, use one of the following options:
tcp:localhost,51433
127.0.0.1,1433
In this example, the named instance is called MyInstance
. Make sure the SQL Server Browser service is running, and use one of the following options:
localhost\MyInstance
127.0.0.1\MyInstance
.\MyInstance
You can connect using a server name or an IP address. In this example, the server name MyServer
resolves to 192.10.1.128
.
To connect to a server on the local network with named pipes, use one of the following options:
MyServer
np:MyServer
Bilješka
On a local area network, connecting with TCP/IP might be faster than with named pipes.
If you're connecting to a server configured with default TCP port 1433
, use one of the following options:
tcp:MyServer
tcp:192.10.1.128
If you're connecting to a server configured with a custom TCP port, such as 51433
, use one of the following options:
MyServer,51433
tcp:MyServer,51433
192.10.1.128,51433
tcp:192.10.1.128,51433
In this example, the named instance is called MyInstance
. Make sure the SQL Server Browser service is running on the server, and use one of the following options:
tcp:MyServer\MyInstance
tcp:192.10.1.128\MyInstance
Once you connect successfully to the Database Engine using a client tool, you can execute a Transact-SQL (T-SQL) query or script.
Savjet
In SQL Server Management Studio and Visual Studio Code, paste or type the query into a new query window.
For more information about running T-SQL queries in client tools, see:
Bilješka
Some tools require a batch separator to know that a query is ready to be executed. For example, you might need to put the GO
separator at the end of a T-SQL query in sqlcmd to make sure that the T-SQL query runs.
Događaji
M03 31 23 - M04 2 23
Najveći događaj učenja jezika SQL, platforme Fabric i platforme Power BI. 31. mart - 2. april Koristite kod FABINSIDER da uštedite 400 dolara.
Registrirajte se danasObučavanje
Modul
Understand client-server communication in PostgreSQL - Training
PostgreSQL is a client-server system, which allows many clients to connect to a central server. In this module you learn how PostgreSQL manages connections from clients, and looking at some common PostgreSQL client tools.
Certifikacija
Microsoft Certified: Azure Database Administrator Associate - Certifications
Administer an SQL Server database infrastructure for cloud, on-premises and hybrid relational databases using the Microsoft PaaS relational database offerings.