SQL Server is sometimes installed as named instances and sometimes will be made to sit on different ports.
The host name , Server name and the instance name can be identified by the SQL functions
Registry:
The host name , Server name and the instance name can be identified by the SQL functions
SELECT SERVERPROPERTY('servername') ServerName ,SERVERPROPERTY('InstanceName') instancename ,SERVERPROPERTY('MachineName') AS HOSTNAME
For the Port number you can read it from the Registry or the ErrorLog
Registry:
SET NOCOUNT ON DECLARE @key VARCHAR(1000) ,@PortNumber VARCHAR(20) IF charindex('\', CONVERT(CHAR(40), SERVERPROPERTY('servername')), 0) <> 0 BEGIN SET @key = 'SOFTWARE\MICROSOFT\Microsoft SQL Server\' + @@servicename + '\MSSQLServer\Supersocketnetlib\TCP' END ELSE BEGIN SET @key = 'SOFTWARE\MICROSOFT\MSSQLServer\MSSQLServer\Supersocketnetlib\TCP' END EXEC master..xp_regread @rootkey = 'HKEY_LOCAL_MACHINE' ,@key = @key ,@value_name = 'Tcpport' ,@value = @PortNumber OUTPUT
Error Log:USE master GO xp_readerrorlog 0 ,1 ,N'Server is listening on' GO
No comments:
Post a Comment