SQL Server 的端口号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1281150/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
port number of SQL Server
提问by George2
I am wondering what ports are used by SQL Server database engine? I need such port number to write configuration scripts to grant access to specific port of the machine installed with SQL Server to make it safe. A related question is whether SQL Server database engine will use one static port number to serve all client requests, or using one port for each request?
我想知道 SQL Server 数据库引擎使用哪些端口?我需要这样的端口号来编写配置脚本以授予对安装了 SQL Server 的机器的特定端口的访问权限以使其安全。一个相关的问题是 SQL Server 数据库引擎是使用一个静态端口号来服务所有客户端请求,还是为每个请求使用一个端口?
BTW: my background is SQL Server 2008 enterprise.
顺便说一句:我的背景是 SQL Server 2008 Enterprise。
thanks in advance, George
提前致谢,乔治
回答by Mark Brackett
The default instance will, by default, listen on tcp/1433. It could possibly also listen on a named pipe (tcp/445) - but I think that must be explicitly enabled these days.
默认情况下,默认实例将侦听 tcp/1433。它也可能侦听命名管道 (tcp/445) - 但我认为这些天必须明确启用。
Named instances, like SQLEXPRESS, listen on a dynamic port. The dynamic port is resolved by the client through SQL Server Resolution Protocol (aka SQL Browser) - which listens on udp/14341. This dynamic port is chosen at first startup, and will generally remain the same through future restarts (stored in the Registry) - but if there's a contention, SQL will choose a new port.
命名实例(如 SQLEXPRESS)侦听动态端口。客户端通过 SQL Server 解析协议(又名 SQL 浏览器)解析动态端口 - 该协议侦听 udp/1434 1。这个动态端口是在第一次启动时选择的,并且在以后的重启中通常会保持不变(存储在注册表中)——但是如果有争用,SQL 将选择一个新端口。
You can, and generally should, configure allinstances of a production SQL server to use a static port. This makes firewalling mucheasier.
您可以并且通常应该将生产 SQL 服务器的所有实例配置为使用静态端口。这使得防火墙更容易。
1The only reason that you have to put the named instance in, say, a connection string is so that the client knows to ask SSRP for the dynamic port. If it's a static or otherwise known port, you can simply point the client to Server=server.com:port
, leaving off the instance name.
1必须将命名实例放入连接字符串中的唯一原因是客户端知道向 SSRP 询问动态端口。如果它是静态或其他已知端口,您可以简单地将客户端指向Server=server.com:port
,而忽略实例名称。
回答by Jared Moore
A very easy and programmatic way is to just to query the local_tcp_port column in sys.dm_exec_connections:
一种非常简单且程序化的方法是仅查询 sys.dm_exec_connections 中的 local_tcp_port 列:
select local_tcp_port from sys.dm_exec_connections where local_tcp_port is not null
If that returns no results then it is probably because the server is on this machine and there are no connections from other machines, so there are no tcp connections.
如果没有返回结果,那么可能是因为服务器在这台机器上,并且没有来自其他机器的连接,所以没有 tcp 连接。
In that case, if you are querying with sqlcmd then just put "tcp:" in front of the server name, e.g.
在这种情况下,如果您使用 sqlcmd 进行查询,则只需将“tcp:”放在服务器名称前面,例如
sqlcmd -E -S tcp:(local)
Or if you are connecting with SqlClient, then you can add "Network Library=dbmssocn" to force tcp, e.g.
或者如果你是用SqlClient连接,那么你可以添加“Network Library=dbmssocn”来强制tcp,例如
string connStr = "Server=(local); Integrated Security=true; Network Library=dbmssocn";
回答by Eric
1433 is what SQL Server uses by default. It has since at least SQL Server 6.0.
1433 是 SQL Server 默认使用的。它至少有 SQL Server 6.0。
Generally, for security reasons, you don't want to open this up to the world. People should be accessing your DB onlythrough an application/web service. Direct SQL Server connections over the tubes are rife with security perils.
通常,出于安全原因,您不想向全世界公开它。人们应该只通过应用程序/网络服务访问您的数据库。通过管道的直接 SQL Server 连接充满了安全隐患。
All sessions will use this port (a la port 80 for a web site), but you can change it, using the SQL Server Configuration Tool, described here.
所有会话都将使用此端口(对于网站来说是端口 80),但您可以使用此处描述的 SQL Server 配置工具更改它。
回答by Chris Miller
:1433 is the default. However, it is possible to change this port, and if you're dealing with multiple instances, each one will have a different port.
:1433 是默认值。但是,可以更改此端口,如果您要处理多个实例,则每个实例都有不同的端口。
A quick Google search turns up the following link:
快速谷歌搜索会出现以下链接:
... and I'm sure Technet will have more information.
...我相信 Technet 会提供更多信息。
回答by keikkeik
Sometimes the port is not 1433
有时端口不是 1433
From http://www.php.net/manual/en/function.mssql-connect.php#76256Look in the registry using regedit.exe at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\SQLEXPRESS\MSSQLServer\SuperSocketNetLib\Tcp.
来自http://www.php.net/manual/en/function.mssql-connect.php#76256使用 regedit.exe 在注册表中查看 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\SQLEXPRESS\MSSQLServer\SuperSocketNetLib\Tcp .
One of the nameValue pairs has name TcpPort and a value, which is the port that the SQL Server is listening on.
nameValue 对之一具有名称 TcpPort 和一个值,该值是 SQL Server 正在侦听的端口。