我正在安装一个需要修改 SQL Server 的新产品。
具体来说,启用 tcp/ip 并打开命名管道。我知道如何手动完成。我想要的是一种通过 SQL 或 C# 代码为新客户自动化执行此操作的方法。
我希望有任何关于正确方向的建议。
您可以使用 C# 和服务器管理对象 (SMO) 来完成此操作。您需要的类位于 Microsoft.SqlServer.Smo 和 Microsoft.SqlServer.WmiManagement 库中。
这是我使用过的 Powershell 片段,它使用相同的对象。希望它能为您指明正确的道路。
$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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)