SQL Query to check port number of SQL Server

  • February 9, 2023

We can use below query to check the port on which SQL Server is listening. DECLARE @InstanceName nvarchar(50) DECLARE @value VARCHAR(100) DECLARE @RegKey_InstanceName nvarchar(500) DECLARE @RegKey nvarchar(500) SET @InstanceName=CONVERT(nVARCHAR,isnull(SERVERPROPERTY(‘INSTANCENAME’),’MSSQLSERVER’)) –For SQL Server 2000 if(SELECT Convert(varchar(1),(SERVERPROPERTY(‘ProductVersion’))))=8 BEGIN if @InstanceName=’MSSQLSERVER’ Begin SET @RegKey=’SOFTWARE\Microsoft\’+@InstanceName+’\MSSQLServer\SuperSocketNetLib\TCP\’ END ELSE BEGIN SET @RegKey=’SOFTWARE\Microsoft\Microsoft SQL Server\’+@InstanceName+’\MSSQLServer\SuperSocketNetLib\TCP\’ END EXECUTE xp_regread @rootkey = ‘HKEY_LOCAL_MACHINE’, @key […]