SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
Development resources, articles, tutorials, code samples, tools and downloads for ASP.Net, SQL Server, Reporting Services, T-SQL, Windows, AWS, SAP HANA and ABAP


Find the Port Number for SQL Server Instance

Default port number for SQL Server connections is 1433. On the other hand, on purpose SQL Server administrators may change the default port number for their SQL Server instances. Or for cases where multiple SQL Server instances are installed on the same server, new instances will use different port numbers than the default port number 1433.

If you have problem to connect to a SQL Server instance using port number 1433, the cause can be the database instance could be using a different port number. To identify the port number on the current SQL Server instance, SQL developers can execute following SQL command.

declare @SQLServerPortNumber nvarchar(10);
exec xp_instance_regread
@rootkey = 'HKEY_LOCAL_MACHINE',
@key = 'Software\Microsoft\Microsoft SQL Server\MSSQLServer\SuperSocketNetLib\Tcp\IpAll',
@value_name = 'TcpDynamicPorts',
@value = @SQLServerPortNumber output;

select @SQLServerPortNumber as "Port Number"
Code

SQL programmers can call xp_instance_regread extended stored procedure to read registry values. The registry key is 'Software\Microsoft\Microsoft SQL Server\MSSQLServer\SuperSocketNetLib\Tcp\IpAll' And the port number we are interested is stored in TcpDynamicPorts

As you can see below, my SQL Server instance (SQL Server 2019 CTP3) is using port number 63449 which is different than the default 1433 port number.

find port number of SQL Server instance by code



SQL Server

SQL Server 2019 Installation
download SQL Server 2019
download SQL Server 2017
download SQL Server 2016
download SQL Server 2014
download SQL Server 2012
MacOS ve SQL Server 2019


Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.