SQL Server – T-SQL To Get Port Number

DECLARE​​ @PortNumber​​ VARCHAR(10),​​ @KeyValue​​ VARCHAR(100)

IF​​ CHARINDEX('\',@@SERVERNAME,0)​​ <>0

BEGIN

SET​​ @KeyValue​​ =​​ 'SOFTWARE\MICROSOFT\Microsoft SQL Server\'+@@SERVICENAME+'\MSSQLServer\Supersocketnetlib\TCP'

END

ELSE

BEGIN

SET​​ @keyValue​​ =​​ 'SOFTWARE\MICROSOFT\MSSQLServer\MSSQLServer \Supersocketnetlib\TCP'

END

--How to read Registry in T-SQL Terms - ROOTKEY, KEY, VALUENAME,VALUE​​ 

EXEC​​ master..xp_regread​​ 'HKEY_LOCAL_MACHINE',@KeyValue,'Tcpport',@value=@PortNumber​​ OUTPUT

 

 

SELECT​​ 'SQLSERVER_NAME: '+@@SERVERNAME​​ +​​ ' : SQL SERVER Port Number:'+CONVERT(VARCHAR(10),

@PortNumber)

 

 

Knowledge worth sharing...Share on linkedin
Linkedin
Share on facebook
Facebook
Share on google
Google
Share on twitter
Twitter
Bookmark the permalink.

Leave a Reply

Leave a Reply

Your email address will not be published. Required fields are marked *