禁止服务器的协议,启用或禁用服务器网络协议

启用或禁用服务器网络协议

06/30/2015

本文内容

所有网络协议都是由 SQL Server 安装程序安装的,可以启用也可以禁用这些网络协议。 本主题介绍如何通过使用 SQL Server 配置管理器或 PowerShell,在 SQL Server 2012 中启用或禁用服务器网络协议。 必须停止并重新启动数据库引擎,更改才能生效。

f12fa940bebc7c5b2b08751cff6a20ad.gif安全说明

在安装 SQL Server Express 过程中,将为 BUILTIN\Users 组添加一个登录名。 这使得计算机的所有通过身份验证的用户能够作为 public 角色的成员访问 SQL Server Express 实例。 可以安全地删除 BUILTIN\Users 登录名,以便将数据库引擎访问限制为具有单独登录名的计算机用户或具有登录名的其他 Windows 组成员的计算机用户。

本主题内容

使用以下工具启用或禁用服务器网络协议:

SQL Server 配置管理器

PowerShell

使用 SQL Server 配置管理器

启用服务器网络协议

在 SQL Server 配置管理器的控制台窗格中,展开**“SQL Server 网络配置”**。

在控制台窗格中,单击**“ 的协议”**。

在细节窗格中,右键单击要更改的协议,再单击**“启用”或“禁用”**。

在控制台窗格中,单击**“SQL Server 服务”**。

在详细信息窗格中,右键单击**“SQL Server ()”,再单击“重新启动”**以停止并重新启动 SQL Server 服务。

ab28d821304de3e19bfaba74f8f1260c.gif[Top]

使用 SQL Server PowerShell

使用 PowerShell 启用服务器网络协议

使用管理员权限打开一个命令提示符。

可以从任务栏启动 Windows PowerShell 2.0,也可以通过依次单击“开始”、“所有程序”、“附件”、“Windows PowerShell”、“Windows PowerShell”来启动。

通过输入 Import-Module “sqlps” 导入 sqlps 模块

执行以下语句以启用 TCP 和 Named Pipes 协议。 将 替换为运行 SQL Server 的计算机的名称。 如果您在配置命名实例,请将 MSSQLSERVER 替换为该实例的名称。

若要禁用协议,请将 IsEnabled 属性设置为 $false。

$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='']/ 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='']/ ServerInstance[@Name='MSSQLSERVER']/ServerProtocol[@Name='Np']"

$Np = $wmi.GetSmoObject($uri)

$Np.IsEnabled = $true

$Np.Alter()

$Np

为本地计算机配置协议

当脚本在本地运行并配置本地计算机时,SQL Server PowerShell 可以通过动态确定本地计算机的名称使脚本更为灵活。 若要检索本地计算机的名称,请将设置 $uri 变量的行替换为以下行。

$uri = "ManagedComputer[@Name='" + (get-item env:\computername).Value + "']/ServerInstance[@Name='MSSQLSERVER']/ServerProtocol[@Name='Tcp']"

使用 SQL Server PowerShell 重新启动数据库引擎

启用或禁用了协议后,必须停止并重新启动数据库引擎才能使更改生效。 执行以下语句,通过使用 SQL Server PowerShell 来停止和启动默认实例。 若要停止和启动命名实例,请将 'MSSQLSERVER' 替换为 'MSSQL$'。

# Get a reference to the ManagedComputer class.

CD SQLSERVER:\SQL\

$Wmi = (get-item .).ManagedComputer

# Get a reference to the default instance of the Database Engine.

$DfltInstance = $Wmi.Services['MSSQLSERVER']

# Display the state of the service.

$DfltInstance

# Stop the service.

$DfltInstance.Stop();

# Wait until the service has time to stop.

# Refresh the cache.

$DfltInstance.Refresh();

# Display the state of the service.

$DfltInstance

# Start the service again.

$DfltInstance.Start();

# Wait until the service has time to start.

# Refresh the cache and display the state of the service.

$DfltInstance.Refresh(); $DfltInstance

ab28d821304de3e19bfaba74f8f1260c.gif[Top]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值