自动打开命名管道和tcp \ ip [英] Automate turning named-pipes and tcp\ip on
问题描述
我正在安装需要修改SQL Server的新产品.
I am working on an install of a new product that requires modifications to SQL Server.
具体来说,启用tcp/ip并打开命名管道.我知道如何手动进行.我想要的是一种通过SQL或C#代码为新客户自动执行此操作的方法.
Specifically, enable tcp/ip and turning on named pipes. I know how to do it manually. What i want is a way to automate this for a new customer though SQL or with C# code.
我希望为正确的方向提供任何建议.
I would love any suggestions for the right direction.
推荐答案
您可以使用C#和服务器管理对象(SMO)来做到这一点.您需要的类在Microsoft.SqlServer.Smo和Microsoft.SqlServer.WmiManagement库中.
You can use C# and Server Management Objects (SMO) to do it. The classes you need are in the Microsoft.SqlServer.Smo and Microsoft.SqlServer.WmiManagement libraries.
这是我使用过的Powershell代码段,它使用了相同的对象.希望它会指出正确的方向.
Here's a Powershell snippet I've used that uses the same objects. Hopefully, it will point you down the right path.
$smo = 'Microsoft.SqlServer.Management.Smo.'
$wmi = new-object ($smo + 'Wmi.ManagedComputer').
# List the object properties, including the instance names.
$Wmi
# Enable the TCP protocol on the default instance.
$uri = "ManagedComputer[@Name='<computer_name>']/ ServerInstance[@Name='MSSQLSERVER']/ServerProtocol[@Name='Tcp']"
$Tcp = $wmi.GetSmoObject($uri)
$Tcp.IsEnabled = $true
$Tcp.Alter()
$Tcp
# Enable the named pipes protocol for the default instance.
$uri = "ManagedComputer[@Name='<computer_name>']/ ServerInstance[@Name='MSSQLSERVER']/ServerProtocol[@Name='Np']"
$Np = $wmi.GetSmoObject($uri)
$Np.IsEnabled = $true
$Np.Alter()
$Np
这篇关于自动打开命名管道和tcp \ ip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!