Home
%3CLINGO-SUB%20id%3D%22lingo-sub-383491%22%20slang%3D%22en-US%22%3ETCP%20listening%20ports%20and%20ENDPOINT%20ports%20behavior%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-383491%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3E%20First%20published%20on%20MSDN%20on%20Nov%2005%2C%202008%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CP%3EEndpoint%20configuration%20seems%20to%20be%20creating%20some%20confusion.%26nbsp%3B%20I%20hope%20that%20this%20will%20clarify%20some%20of%20the%20behavior%20as%20it%20applies%20to%20TCP%20endpoints.%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3EWith%20a%20default%20configuration%20of%20SQL%20Server%2C%20try%20the%20following%3A%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%26gt%3B%20select%20name%2C%20port%2C%20is_dynamic_port%2C%20state%20from%20sys.tcp_endpoints%20%3CBR%20%2F%3E%20%26gt%3B%20go%20%3CBR%20%2F%3E%20name%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3Bport%20is_dynamic_port%20state%20%3CBR%20%2F%3E%20---------------------------%20----%20---------------%20-----%20%3CBR%20%2F%3E%20Dedicated%20Admin%20Connection%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%26nbsp%3B0%20%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B1%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B0%20%3CBR%20%2F%3E%20TSQL%20Default%20TCP%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B0%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B1%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B0%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3EAt%20first%2C%20it%20may%20seem%20that%20the%20%E2%80%9Cport%E2%80%9D%20value%20in%20this%20table%20is%20incorrect.%26nbsp%3B%20The%20server%20is%20listening%20on%20port%201433%2C%20not%20port%200.%26nbsp%3B%20In%20addition%2C%20if%20your%20instance%20is%20configured%20to%20listen%20on%20different%20or%20multiple%20ports%2C%20they%20do%20not%20appear%20here.%26nbsp%3B%20Confused%3F%26nbsp%3B%20I%20was%20too.%26nbsp%3B%20(Also%2C%20note%20that%20state%200%20means%20%22started%22%20and%20state%201%20means%20%22stopped%22).%3C%2FP%3E%0A%20%20%3CP%3EThe%20behavior%20you%20are%20seeing%20is%2C%20in%20fact%2C%20by%20design.%20A%20zero%20for%20a%20port%20value%20is%20effectively%20a%20wildcard%2C%20matching%20any%20endpoint%20of%20that%20type%20that%20doesn't%20have%20a%20more%20specific%20rule.%26nbsp%3B%20The%20endpoint%20configuration%20does%20not%20specify%20what%20ports%20clients%20can%20use%20to%20connect%20to%20the%20server.%26nbsp%3B%20Rather%2C%20it%20specifies%20the%20rules%20to%20apply%20to%20a%20connection%20when%20it%20is%20made.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20So%2C%20the%20default%20TCP%20port%20or%20any%20other%20TCP%20port%20with%20no%20specific%20endpoint%20defined%20will%20use%20this%20default%20rule.%20Here%20is%20an%20example%20of%20how%20this%20works%3A%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3EFirst%2C%20issue%20%22alter%20endpoint%20%5BTSQL%20Default%20TCP%5D%20state%20%3D%20stopped%22%20and%20see%20that%20we%20can%20no%20longer%20connect%20via%20TCP%20to%20the%20server%3A%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%26gt%3B%20select%20name%2C%20port%2C%20is_dynamic_port%2C%20state%20from%20sys.tcp_endpoints%20%3CBR%20%2F%3E%20%26gt%3B%20go%20%3CBR%20%2F%3E%20name%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3Bport%20is_dynamic_port%20state%20%3CBR%20%2F%3E%20---------------------------%20----%20---------------%20-----%20%3CBR%20%2F%3E%20Dedicated%20Admin%20Connection%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%26nbsp%3B0%20%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B1%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B0%20%3CBR%20%2F%3E%20TSQL%20Default%20TCP%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B0%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B1%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B1%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3EFor%20now%2C%20re-enable%20that%20port%20using%20%22alter%20endpoint%20%5BTSQL%20Default%20TCP%5D%20state%20%3D%20started%22%20and%20we%20can%20connect%20again%20using%20TCP%20on%20the%20default%20port.%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3EIf%20you%20now%20use%20SQLServer%20Configuration%20Manager%20to%20add%20a%20new%20port%20for%20SQLServer%20to%20listen%20on%2C%20say%2C%20port%206060%20and%20restart%2C%20you%20can%20now%20connect%20using%20TCP%20on%20port%201433%20or%20port%206060.%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3EThen%20issue%20%22alter%20endpoint%20%5BTSQL%20Default%20TCP%5D%20state%20%3D%20stopped%22%20and%20we%20can%20no%20longer%20connect%20on%20either%20port.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Then%20issue%20%22create%20endpoint%20%5BMyEndpoint%5D%20state%20%3D%20stopped%20as%20tcp%20(listener_port%20%3D%206060)%20FOR%20tsql%20()%22%20and%20we%20still%20can't%20connect%20on%20either%20port%2C%20because%20they%20are%20both%20still%20%22stopped%22%3A%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%26gt%3B%20select%20name%2C%20port%2C%20is_dynamic_port%2C%20state%20from%20sys.tcp_endpoints%20%3CBR%20%2F%3E%20%26gt%3B%20go%20%3CBR%20%2F%3E%20name%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3Bport%20is_dynamic_port%20state%20%3CBR%20%2F%3E%20---------------------------%20----%20---------------%20-----%20%3CBR%20%2F%3E%20Dedicated%20Admin%20Connection%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%26nbsp%3B0%20%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B1%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B0%20%3CBR%20%2F%3E%20TSQL%20Default%20TCP%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B0%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B1%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B1%20%3CBR%20%2F%3E%20MyEndpoint%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B6060%20%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B0%20%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B1%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Now%20issue%20%22alter%20endpoint%20%5BTSQL%20Default%20TCP%5D%20state%20%3D%20started%22%20and%20we%20can%20connect%20on%201433%20but%20not%20on%206060.%26nbsp%3B%20This%20is%20because%20there%20is%20a%20specific%20rule%20for%20port%206060%20which%20is%20applied.%26nbsp%3B%20On%20port%201433%2C%20there%20is%20no%20specific%20rule%2C%20so%20the%20default%20rules%20apply%20and%20the%20connection%20is%20allowed.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20If%20we%20now%20issue%20%22alter%20endpoint%20%5BMyEndpoint%5D%20state%20%3D%20started%22%20and%20we%20can%20connect%20via%20TCP%20on%20both%20port%201433%20and%20port%206060.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Finally%2C%20if%20we%20issue%20%22alter%20endpoint%20%5BTSQL%20Default%20TCP%5D%20state%20%3D%20stopped%22%20and%20we%20can%20connect%20via%20TCP%20on%20port%206060%20but%20not%20on%20port%201433.%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3EDavid%20Benoit%20%3CBR%20%2F%3E%20SQL%20Server%20Protocols%20%3CBR%20%2F%3E%20Disclaimer%3A%20This%20posting%20is%20provided%20%22AS%20IS%22%20with%20no%20warranties%2C%20and%20confers%20no%20rights%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-383491%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20MSDN%20on%20Nov%2005%2C%202008%20Endpoint%20configuration%20seems%20to%20be%20creating%20some%20confusion.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-383491%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESQLServerProtocols%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft
First published on MSDN on Nov 05, 2008

Endpoint configuration seems to be creating some confusion.  I hope that this will clarify some of the behavior as it applies to TCP endpoints.

With a default configuration of SQL Server, try the following:

> select name, port, is_dynamic_port, state from sys.tcp_endpoints
> go
name                        port is_dynamic_port state
--------------------------- ---- --------------- -----
Dedicated Admin Connection     0               1     0
TSQL Default TCP               0               1     0

At first, it may seem that the “port” value in this table is incorrect.  The server is listening on port 1433, not port 0.  In addition, if your instance is configured to listen on different or multiple ports, they do not appear here.  Confused?  I was too.  (Also, note that state 0 means "started" and state 1 means "stopped").

The behavior you are seeing is, in fact, by design. A zero for a port value is effectively a wildcard, matching any endpoint of that type that doesn't have a more specific rule.  The endpoint configuration does not specify what ports clients can use to connect to the server.  Rather, it specifies the rules to apply to a connection when it is made.

So, the default TCP port or any other TCP port with no specific endpoint defined will use this default rule. Here is an example of how this works:

First, issue "alter endpoint [TSQL Default TCP] state = stopped" and see that we can no longer connect via TCP to the server:

> select name, port, is_dynamic_port, state from sys.tcp_endpoints
> go
name                        port is_dynamic_port state
--------------------------- ---- --------------- -----
Dedicated Admin Connection     0               1     0
TSQL Default TCP               0               1     1

For now, re-enable that port using "alter endpoint [TSQL Default TCP] state = started" and we can connect again using TCP on the default port.

If you now use SQLServer Configuration Manager to add a new port for SQLServer to listen on, say, port 6060 and restart, you can now connect using TCP on port 1433 or port 6060.

Then issue "alter endpoint [TSQL Default TCP] state = stopped" and we can no longer connect on either port.

Then issue "create endpoint [MyEndpoint] state = stopped as tcp (listener_port = 6060) FOR tsql ()" and we still can't connect on either port, because they are both still "stopped":

> select name, port, is_dynamic_port, state from sys.tcp_endpoints
> go
name                        port is_dynamic_port state
--------------------------- ---- --------------- -----
Dedicated Admin Connection     0               1     0
TSQL Default TCP               0               1     1
MyEndpoint                  6060               0     1

Now issue "alter endpoint [TSQL Default TCP] state = started" and we can connect on 1433 but not on 6060.  This is because there is a specific rule for port 6060 which is applied.  On port 1433, there is no specific rule, so the default rules apply and the connection is allowed.

If we now issue "alter endpoint [MyEndpoint] state = started" and we can connect via TCP on both port 1433 and port 6060.

Finally, if we issue "alter endpoint [TSQL Default TCP] state = stopped" and we can connect via TCP on port 6060 but not on port 1433.

David Benoit
SQL Server Protocols
Disclaimer: This posting is provided "AS IS" with no warranties, and confers no rights