Afisare port sql server

Configurare noua (How To)

Situatie

Mai jos este o procedura ce returneaza portul pe care ruleaza sql serverul pe care este rulata procedura.

Solutie

create procedure FindSqlPortNumber_prc

as

DECLARE @port varchar(15)
DECLARE @value_name varchar(15)
DECLARE @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=@port OUTPUT

Print ‘The Port Number is ‘+ @port

Tip solutie

Permanent

Voteaza

(21 din 48 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?