방법: 서버 네트워크 프로토콜 설정 또는 해제(SQL Server PowerShell)

TCP 및 명명된 파이프 네트워크 프로토콜은 SQL Server 설치 시 설치되지만 필요에 따라 프로토콜을 사용하지 않도록 설정할 수 있습니다. 다음 PowerShell 스크립트를 사용하거나 SQL Server 구성 관리자를 사용하여 네트워크 프로토콜을 활성화하거나 비활성화할 수 있습니다. 프로토콜 변경 사항을 적용하려면 SQL Server 데이터베이스 엔진를 중지한 후 다시 시작해야 합니다.

PowerShell에 대한 자세한 내용은 SQL Server PowerShell 개요를 참조하십시오. SQL Server 구성 관리자를 사용하여 프로토콜을 관리하는 방법에 대한 자세한 내용은 방법: 서버 네트워크 프로토콜 설정 또는 해제(SQL Server 구성 관리자)를 참조하십시오.

SQL Server PowerShell (SQLPS.exe) 유틸리티는 PowerShell 공급자와 cmdlet이 로드되어 등록된 SQL Server 세션을 시작합니다. SQL Server PowerShell 대신 PowerShell(PowerShell.exe)을 실행할 경우 먼저 다음 문을 실행하여 필요한 어셈블리를 수동으로 로드해야 합니다.

# Load the assemblies
[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")
[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.SqlWmiManagement")

다음 스크립트는 프로토콜을 사용하도록 설정합니다. 프로토콜을 사용하지 않으려면 IsEnabled 속성을 $false로 설정합니다.

SQL Server PowerShell을 사용하여 서버 네트워크 프로토콜을 활성화하려면

  1. 관리자 권한으로 명령 프롬프트를 엽니다.

  2. SQL Server PowerShell을 시작하려면 명령 프롬프트에서 sqlps.exe를 입력합니다.

  3. 다음 문을 실행하여 TCP 및 명명된 파이프 프로토콜을 모두 사용하도록 설정합니다. <computer_name>을 SQL Server가 실행 중인 컴퓨터의 이름으로 바꿉니다. 명명된 인스턴스를 구성할 경우 MSSQLSERVER를 인스턴스의 이름으로 바꿉니다.

    $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
    

로컬 컴퓨터의 프로토콜을 구성하려면

  • 스크립트가 로컬로 실행되고 로컬 컴퓨터를 구성할 경우 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$<instance_name>'으로 바꿉니다.

    # Get a reference to the ManagedComputer class.
    CD SQLSERVER:\SQL\<computer_name>
    $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