|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Friday, June 14, 2013 6:35 AM
Points: 306,
Visits: 1,020
|
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Today @ 3:33 PM
Points: 18,858,
Visits: 12,443
|
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Today @ 7:34 AM
Points: 33,
Visits: 774
|
|
Loved the script, as we come across all types of environments and frequently need the extra info.
I added a slight tweak to include SQL Version as part of the output:
-- Show instance, SQL version, and port number for SQL 2000/2005/2008/2008R2 Version
set nocount on go DECLARE @SqlPort Nvarchar(10) DECLARE @instance_name Nvarchar(30) DECLARE @reg_key Nvarchar(500) DECLARE @value_name Nvarchar(20) DECLARE @ProductVersion Nvarchar(10)
-- Scan for SQL 2008R2 if left(CAST(SERVERPROPERTY('ProductVersion')AS sysname),5) = '10.50' BEGIN
select @ProductVersion = '2008R2' select @instance_name = CAST(SERVERPROPERTY('instancename')AS sysname)
if @instance_name is NULL BEGIN set @reg_key = 'SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQLServer\SuperSocketNetLib\AdminConnection\Tcp' --END --ELSE BEGIN --set @reg_key = 'SOFTWARE\Microsoft\Microsoft SQL Server\' + @instance_name + '\MSSQLServer\SuperSocketNetLib\Tcp' END
EXEC master..xp_regread @rootkey='HKEY_LOCAL_MACHINE', @key=@reg_key, @value_name='TcpDynamicPorts', @value=@SqlPort output
select CAST(SERVERPROPERTY('ServerName')AS sysname) as ServerName, @ProductVersion as SQLVersion, @SqlPort as Port
END
-- Scan for SQL 2008 if left(CAST(SERVERPROPERTY('ProductVersion')AS sysname),5) = '10.0.' BEGIN
select @ProductVersion = '2008' select @instance_name = CAST(SERVERPROPERTY('instancename')AS sysname)
if @instance_name is NULL BEGIN set @reg_key = 'SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQLServer\SuperSocketNetLib\AdminConnection\Tcp' --END --ELSE BEGIN --set @reg_key = 'SOFTWARE\Microsoft\Microsoft SQL Server\' + @instance_name + '\MSSQLServer\SuperSocketNetLib\Tcp' END
EXEC master..xp_regread @rootkey='HKEY_LOCAL_MACHINE', @key=@reg_key, @value_name='TcpDynamicPorts', @value=@SqlPort output
select CAST(SERVERPROPERTY('ServerName')AS sysname) as ServerName, @ProductVersion as SQLVersion, @SqlPort as Port
END
-- Scan for SQL 2005 if left(CAST(SERVERPROPERTY('ProductVersion')AS sysname),1) = '9' BEGIN
select @ProductVersion = '2005' select @instance_name = CAST(SERVERPROPERTY('instancename')AS sysname)
if @instance_name is NULL BEGIN set @reg_key = 'SOFTWARE\Microsoft\MSSQLServer\MSSQlServer\SuperSocketNetLib\Tcp' END ELSE BEGIN set @reg_key = 'SOFTWARE\Microsoft\Microsoft SQL Server\' + @instance_name + '\MSSQLServer\SuperSocketNetLib\Tcp' END
EXEC master..xp_regread @rootkey='HKEY_LOCAL_MACHINE', @key=@reg_key, @value_name='TcpPort', @value=@SqlPort output
select CAST(SERVERPROPERTY('ServerName')AS sysname) as ServerName, @ProductVersion as SQLVersion, @SqlPort as Port
END
-- Scan for SQL 2000 if left(CAST(SERVERPROPERTY('ProductVersion')AS sysname),1) = '8' BEGIN
select @ProductVersion = '2000' Create table #Port_2000 (value nvarchar(20),Data nVarchar(10)) insert into #Port_2000 exec master..xp_instance_regread 'HKEY_LOCAL_MACHINE', 'SOFTWARE\Microsoft\MSSQLServer\MSSQLServer\Supersocketnetlib\tcp', 'tcpPort' select @SqlPort = Data from #Port_2000 select CAST(SERVERPROPERTY('ServerName')AS sysname) as ServerName, @ProductVersion as SQLVersion, @SqlPort as Port drop table #Port_2000
END
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Friday, June 14, 2013 6:35 AM
Points: 306,
Visits: 1,020
|
|
Nice addition My original version had SQL server version but I collect that information with another script so I removed it.
Glad to see that other find the code useful.
Rudy
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Wednesday, June 05, 2013 2:06 PM
Points: 574,
Visits: 685
|
|
Doesn't seem to work on clustered instances..at least not the 3 I tried. 
Very handy in any case though for all non-clustered servers. Going to get much use out of this.
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Friday, June 14, 2013 6:35 AM
Points: 306,
Visits: 1,020
|
|
The code will not work on a cluster unless you run it from the node(s) and not from the virtual SQL server.
Give it a try and let us know.
Rudy
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Tuesday, June 11, 2013 4:50 PM
Points: 381,
Visits: 674
|
|
Rudy Panigas (1/21/2011) The code will not work on a cluster unless you run it from the node(s) and not from the virtual SQL server.
Give it a try and let us know.
Rudy
Rudy, it seemed to work for me against my SQL 2000 cluster virtual... Maybe it doesn't work against newer versions?
____________________________________________________________________________________________ Remember as you walk down lifes road, don't forget to stop and pee on the bushes - Thordog
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Saturday, April 20, 2013 10:15 AM
Points: 1,
Visits: 127
|
|
If you have access to SQL server error logs...which any DBA would....just check the time when the SQL server was last started, and in the startup parameters, it gives the port that the instance is listening on. or open sql server configuration manager, and click on the tcp properties where you can set the port on which SQL should listen.
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Friday, June 14, 2013 6:35 AM
Points: 306,
Visits: 1,020
|
|
Thordog (1/21/2011)
Rudy Panigas (1/21/2011) The code will not work on a cluster unless you run it from the node(s) and not from the virtual SQL server.
Give it a try and let us know.
RudyRudy, it seemed to work for me against my SQL 2000 cluster virtual... Maybe it doesn't work against newer versions?
Glad it worked.
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Friday, June 14, 2013 6:35 AM
Points: 306,
Visits: 1,020
|
|
anand13685 (2/16/2011) If you have access to SQL server error logs...which any DBA would....just check the time when the SQL server was last started, and in the startup parameters, it gives the port that the instance is listening on. or open sql server configuration manager, and click on the tcp properties where you can set the port on which SQL should listen.
Good point. I was doing that before and thought that there must be an easier way. So I worked on some T-SQL code and that's how this code was created.
Thanks
|
|
|
|