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

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

03/14/2017

本文内容

适用于:

719f28649793c602f9270966b5ed5c39.pngSQL Server(所有支持的版本)

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

重要

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

警告

SQL Server 至 SQL Server 2014 (12.x) 的 SQL Server 和 Microsoft 数据提供商在默认情况下仅支持 TLS 1.0 和 SSL 3.0。 如果通过更改操作系统 SChannel 层强制使用其他协议(如 TLS 1.1 或 TLS 1.2),与 SQL Server 的连接可能会失败,除非已安装相应的更新,将 TLS 1.1 和 1.2 的支持添加到 SQL Server,此处列出了这些更新。 从 SQL Server 2016 (13.x) 开始,SQL Server 的所有发布版本均包括 TLS 1.2 支持,无需安全其他更新。

本主题内容

使用 SQL Server 配置管理器

启用服务器网络协议

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

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

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

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

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

使用 SQL Server PowerShell

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

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

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

通过输入“sqlps”导入“Import-Module “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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值