Using the extended stored procedure
One of the procedure which is created by default in the database for accessing the network information can be used to get the port number of running instance and the name of the procedure is xp_regread.
The code carried by the procedure is as follows-
Code:
DECLARE @tcp_port nvarchar(5)
EXEC xp_regread
@rootkey = ‘HKEY_LOCAL_MACHINE’,
@key = ‘SOFTWARE\MICROSOFT\MSSQLSERVER\MSSQLSERVER\SUPERSOCKETNETLIB\TCP’,
@value_name = ‘TcpPort’,
@value = @tcp_port OUTPUT
select @tcp_port
Execute this code within the SQL statement and get the port number of current instance.
Bookmarks