Freigeben über


Aktivieren des TCP-Protokolls

Hinweis

Es gibt zwei SQL Server PowerShell-Module: SqlServer und SQLPS.

Das SqlServer-Modul ist das zu verwendende aktuelle PowerShell-Modul.

Das SQLPS-Modul ist zwar in der SQL Server-Installation (für die Abwärtskompatibilität) enthalten, wird jedoch nicht mehr aktualisiert.

Das SqlServer-Modul enthält aktualisierte Versionen der Cmdlets in SQLPS sowie neue Cmdlets zur Unterstützung der neuesten SQL-Funktionen.

Installieren Sie das SqlServer-Modul aus dem PowerShell-Katalog.

Weitere Informationen finden Sie unter SQL Server PowerShell.

So aktivieren Sie das TCP-Protokoll, wenn eine Verbindung mit der Konsole mit SQLPS hergestellt wird.

  1. Öffnen Sie eine Eingabeaufforderung, und geben Sie Folgendes ein:

    C:\> SQLPS.EXE
    

    Tipp

    Wenn SQLPS nicht gefunden wird, müssen Sie möglicherweise eine neue Eingabeaufforderung öffnen oder sich einfach abmelden und sich wieder anmelden.

  2. Geben Sie an der PowerShell-Eingabeaufforderung Folgendes ein:

    # Instantiate a ManagedComputer object that exposes primitives to control the
    # Installation of SQL Server on this machine.
    
    $wmi = New-Object 'Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer' localhost
    
    # Enable the TCP protocol on the default instance. If the instance is named,
    # replace MSSQLSERVER with the instance name in the following line.
    
    $tcp = $wmi.ServerInstances['MSSQLSERVER'].ServerProtocols['Tcp']
    $tcp.IsEnabled = $true
    $tcp.Alter()
    
    # You need to restart SQL Server for the change to persist
    # -Force takes care of any dependent services, like SQL Agent.
    # Note: If the instance is named, replace MSSQLSERVER with MSSQL$ followed by
    # the name of the instance (e.g., MSSQL$MYINSTANCE)
    
    Restart-Service -Name MSSQLSERVER -Force
    

Aktivieren des TCP-Protokolls, wenn eine Verbindung mit der Konsole hergestellt, aber nicht SQLPS verwendet wird

  1. Öffnen Sie eine Eingabeaufforderung, und geben Sie Folgendes ein:

    C:\> PowerShell.exe
    
  2. Geben Sie an der PowerShell-Eingabeaufforderung Folgendes ein:

    # Get access to SqlWmiManagement DLL on the machine with SQL
    # we are on, which is where SQL Server was installed.
    # Note: This is installed in the GAC by SQL Server Setup.
    
    [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SqlWmiManagement')
    
    # Instantiate a ManagedComputer object that exposes primitives to control the
    # Installation of SQL Server on this machine.
    
    $wmi = New-Object 'Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer' localhost
    
    # Enable the TCP protocol on the default instance. If the instance is named,
    # replace MSSQLSERVER with the instance name in the following line.
    
    $tcp = $wmi.ServerInstances['MSSQLSERVER'].ServerProtocols['Tcp']
    $tcp.IsEnabled = $true
    $tcp.Alter()
    
    # You need to restart SQL Server for the change to persist
    # -Force takes care of any dependent services, like SQL Agent.
    # Note: If the instance is named, replace MSSQLSERVER with MSSQL$ followed by
    # the name of the instance (e.g., MSSQL$MYINSTANCE)
    
    Restart-Service -Name MSSQLSERVER -Force