获取/设置SQL Server实例设置

时间:2010-05-12 15:41:27

标签: c# sql-server tsql

有没有办法通过C#或TSQL获取SQL Server实例的设置?然后将这些设置应用于另一个SQL Server?

由于

1 个答案:

答案 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')