有没有办法通过C#或TSQL获取SQL Server实例的设置?然后将这些设置应用于另一个SQL Server?
由于
答案 0 :(得分:0)
获取Sql Server实例是
Declare @key Varchar(100), @PortNumber varchar(20)
if charindex('\',CONVERT(char(20), 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
SELECT CONVERT(char(20), SERVERPROPERTY('servername')) ServerName,
CONVERT(char(20), SERVERPROPERTY('InstanceName')) instancename
OR
SELECT SERVERPROPERTY('InstanceName')