发布-日期: 2016年11月04日 (评论)
使用此SQL逻辑可以省去大量的点击。这将找到多实例SQL Server上安装的每个SQL Server实例的所有端口。此逻辑假定用于默认SQL实例的默认端口为1433。
Save a bunch of clicks with this SQL logic. This will find all the ports for each SQL Server instance installed on your multi-instance SQL Server. This logic assumes the default port of 1433 is being used for the default SQL instance.
use master;
set nocount on
declare @sql_instances table
(
[rootkey] varchar(255)
, [value] varchar(255)
)
insert into @sql_instances
exec master.dbo.xp_instance_regenumvalues
@rootkey = N'HKEY_LOCAL_MACHINE'
, @key = N'SOFTWARE\\Microsoft\\Microsoft SQL Server\\Instance Names\\SQL';
declare db_cursor cursor for select upper([rootkey]), upper([value]) from @sql_instances
declare @instance_name varchar(255)
declare @instance_path varchar(255)
open db_cursor;
fetch next from db_cursor into @instance_name, @instance_path
while @@fetch_status = 0
begin
declare @port_table table
(
[Instance] varchar(255)
, [Port] int
)
declare @port varchar(50)
declare @key varchar(255) = 'software\microsoft\microsoft sql server\' + @instance_path + '\mssqlserver\supersocketnetlib\tcp\ipall'
exec master..xp_regread
@rootkey = 'hkey_local_machine'
, @key = @key
, @value_name = 'tcpdynamicports'
, @value = @port output
insert into @port_table
select
'Instance' = @instance_name
, 'Port' = isnull(convert(varchar(10), @port), 1433)
fetch next from db_cursor into @instance_name, @instance_path
end;
close db_cursor
deallocate db_cursor;
select * from @port_table
Build Quality | Build History | ||||
---|---|---|---|---|---|
- 李聪明的数据库 Lee's Clever Data
- Mike的数据库宝典 Mikes Database Collection
- 李聪明的数据库 "Lee Songming"