更改SQL Server默认TCP端口 [英] Change SQL Server default TCP port

查看:339
本文介绍了更改SQL Server默认TCP端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改服务器中SQL Server的默认TCP端口。我知道默认端口是1433,并且我知道如何使用UI,但是我需要诸如注册表或批处理文件之类的代码或诸如Delphi,VB,C#之类的编程语言

I want to change the SQL Server default TCP port in server. I know the default port is 1433, and I know how do this with UI, but I need a code such as registry or batch file or programming language like Delp VB, C#

谢谢您

推荐答案

这是我在Powershell脚本中所拥有的内容,该脚本是我的服务器工作的一部分,以前是通过几个工作完成的:

Here's what I have in a Powershell script that's part of my server build from a couple of jobs ago:

param (
    [string]$server_name = $(Read-Host -prompt Server)
)
$Machine = new-object 'Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer' $server_name

$instance = $Machine.ServerInstances[ 'MSSQLSERVER' ];

$instance.ServerProtocols[ 'Tcp' ].IsEnabled = $true;
$instance.ServerProtocols[ 'Tcp' ].Alter();

$ipAll = $instance.ServerProtocols['Tcp'].IPAddresses['IPAll'];
$ipAll.IPAddressProperties['TcpPort'].Value = "14330";
$ipAll.IPAddressProperties['TcpDynamicPorts'].Value = ""
$instance.ServerProtocols['Tcp'].Alter();

它假定SQL Server的非命名实例,并且要设置的端口为 14330 。进行调整以满足您的要求。

It assumes a non-named instance of SQL Server and that the port you want to set is 14330. Adjust to meet your requirements.

这篇关于更改SQL Server默认TCP端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆