Abilitare il protocollo TCP

Annotazioni

Sono disponibili due moduli di SQL Server PowerShell. SqlServer e SQLPS.

Il modulo SqlServer è il modulo di PowerShell corrente da usare.

Il modulo SQLPS è incluso nell'installazione di SQL Server (per compatibilità con le versioni precedenti) ma non viene più aggiornato.

Il modulo SqlServer contiene versioni aggiornate dei cmdlet in SQLPS e include nuovi cmdlet per supportare le funzionalità SQL più recenti.

Installare il modulo SqlServer da PowerShell Gallery.

Per altre informazioni, vedere SQL Server PowerShell.

Per abilitare il protocollo TCP quando si è connessi alla console con SQLPS.

  1. Aprire un prompt dei comandi e digitare:

    C:\> SQLPS.EXE
    

    Suggerimento

    Se SQLPS non viene trovato, potrebbe essere necessario aprire un nuovo prompt dei comandi o semplicemente disconnettersi ed eseguire nuovamente l'accesso.

  2. Al prompt dei comandi di PowerShell digitare:

    # 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
    

Abilitare il protocollo TCP quando si è connessi alla console ma non si usa SQLPS

  1. Aprire un prompt dei comandi e digitare:

    C:\> PowerShell.exe
    
  2. Al prompt dei comandi di PowerShell digitare:

    # 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