Skip to main content

Detects if SQL Server Command Mode (SQLCMD) is enabled, and disables script execution if SQLCMD mode is not supported.

/* ----------------------------------------------------------------------------
    Detect SQLCMD mode and disable script execution if SQLCMD mode
    is not supported.

    NOTE: To re-enable the script after enabling SQLCMD mode,
    execute the following:

    set noexec off;
    go
---------------------------------------------------------------------------- */

:setvar IsSqlCmdEnabled "True"
go

if N'$(IsSqlCmdEnabled)' not like N'True'
    begin
        print N'SQLCMD mode must be enabled to successfully execute this script.';
        print N'Disabling script execution.';
        set noexec on;
    end;
go