Search

Friday, April 12, 2013

Findout The TCP Port of an Instance

It will help you determine the TCP Port for an instance.

DECLARE @key VARCHAR(50), @RegistryPath VARCHAR(200)
 IF (SERVERPROPERTY('INSTANCENAME')) IS NULL
 BEGIN
 SET @RegistryPath='Software\Microsoft\MSSQLServer\MSSQLServer\SuperSocketNetLib\Tcp\'
 END
 ELSE
BEGIN
 SET @RegistryPath='Software\Microsoft\Microsoft SQL Server\'+CONVERT(VARCHAR(25),SERVERPROPERTY('INSTANCENAME'))+'\MSSQLServer\SuperSocketNetLib\Tcp\'
 END
 EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE', @RegistryPath, 'tcpPort'

No comments:

Post a Comment