SQL Server 執行 xp_cmdshell 錯誤排解

問題說明

在 SSMS 執行 xp_cmdshell 出現以下的錯誤訊息

SQL Server blocked access to procedure 'sys.xp_cmdshell' of component 'xp_cmdshell' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'xp_cmdshell' by using sp_configure. For more information about enabling 'xp_cmdshell', search for 'xp_cmdshell' in SQL Server Books Online.

 

解決方式

參考 Enabling xp_cmdshell in SQL Server

執行 T-SQL

-- this turns on advanced options and is needed to configure xp_cmdshell

exec sp_configure 'show advanced options', '1'

RECONFIGURE

-- this enables xp_cmdshell

exec sp_configure 'xp_cmdshell', '1'

RECONFIGURE

 

或從 SSMS 介面調整設定

2021-03-12_14-56-36

2021-03-12_14-57-00