SQL Server 已封鎖元件 'xp_cmdshell' 的 程序 'sys.xp_cmdshell' 之存取,該如何處理?

一、問題描述

使用 xp_cmdshell  出現如下錯誤訊息,該如何處理?

訊息 15281,層級 16,狀態 1,程序 xp_cmdshell,行 1
SQL Server 已封鎖元件 'xp_cmdshell' 的 程序 'sys.xp_cmdshell' 之存取,因為此元件已經由此伺服器的安全性組態關閉。系統管理員可以使用 sp_configure 來啟用 'xp_cmdshell' 的使用。如需有關啟用 'xp_cmdshell' 的詳細資訊,請參閱《SQL Server 線上叢書》中的<介面區組態>(Surface Area Configuration)。

二、從 Facet 開啟或關閉 xp_cmdshell

1. 開啟 SQL Server Management Studio,連接伺服器後,如下圖按滑鼠右鍵,選擇 [Facet]。

2. 此時出現 [檢視 facet] 視窗,找出 [XPCmdShellEnabled] 選擇 [True]。

三、透過 SQL 語法開啟或關閉 xp_cmdshell

01 -- 開啟 xp_cmdshell
02 EXEC sp_configure 'show advanced options', 1;
03 RECONFIGURE;
04 EXEC sp_configure 'xp_cmdshell', 1;
05 RECONFIGURE;
06   
07 -- 關閉 xp_cmdshell
08 EXEC sp_configure 'show advanced options', 1;
09 RECONFIGURE;
10 EXEC sp_configure 'xp_cmdshell', 0;
11 RECONFIGURE;
原文地址:https://www.cnblogs.com/luoyaoquan/p/2052599.html