Pages

Tuesday, May 3, 2011

How to get port number of SQL

Problem:
FAST Search is asking for the port number of SQL for the install. If it isn't the default, what is it and how do I know?
Solution:
Execute the following query in SQL:
DECLARE @test VARCHAR(15) ,
@value_name VARCHAR(15) ,
@RegistryPath VARCHAR(200)
IF ( CHARINDEX('\', @@SERVERNAME) <> 0 ) -- Named Instance
BEGIN
SET @RegistryPath = 'SOFTWARE\Microsoft\Microsoft SQL Server\' +
RIGHT(@@SERVERNAME,
LEN(@@SERVERNAME) - CHARINDEX('\', @@SERVERNAME)) +
'\MSSQLServer\SuperSocketNetLib\Tcp'
END
ELSE -- Default Instance
BEGIN
SET @RegistryPath = 'SOFTWARE\Microsoft\MSSQLServer\MSSQLServer\SuperSocketNetLib\Tcp'
END
EXEC master..xp_regread
@rootkey = 'HKEY_LOCAL_MACHINE' ,
@key = @RegistryPath ,
@value_name = 'TcpPort' ,
@value = @test OUTPUT
PRINT 'The Port Number is ' + CHAR(13) + @test

Result:
In the messages, you will see this:
The port Number is
12345

1 comment: