數(shù)據(jù)庫由SQL2000升級為SQL2005,再運行以前開發(fā)的程序時報錯,此程序執(zhí)行一存儲過程,見用SQL語句拷貝文件。
程序報錯,提示:
SQL Server 阻止了對組件'xp_cmdshell' 的過程'sys.xp_cmdshell' 的訪問,因為此組件已作為此服務器安全配置的一部分而被關閉。系統(tǒng)管理員可以通過使用sp_configure 啟用'xp_cmdshell'。有關啟用'xp_cmdshell' 的詳細信息,請參閱SQL Server 聯(lián)機叢書中的"外圍應用配置器"。
解決方法:
方法一:
啟動外圍應用配置器工具。依次運行[開始]菜單-[程序]-[Microsoft SQL Server 2005]-[配置工具]-[SQL Server 外圍應用配置器]。單擊“配置外圍應用”旁邊的鏈接,選擇服務器,默認值為 localhost。選擇“功能的外圍應用配置器”,啟用'xp_cmdshell'選項打勾即可。
方法二:
用語句啟用'xp_cmdshell'。運行如下的SQL語句:
sp_configure 'xp_cmdshell', 1;
go
reconfigure;
go
運行完畢,即可啟用'xp_cmdshell'。
注:若要用 sp_configure 配置高級選項,必須首先在 "show advanced options" 選項設置為 1 的情況下運行 sp_configure,然后運行 RECONFIGURE:
運行下面語句后則執(zhí)行成功:
sp_configure 'show advanced options', 1;
go
reconfigure;
go
---------
可通過下面語句查看高級選項
SELECT * FROM sys.configurations
ORDER BY name ;
GO
進行如上修改后,再運行程序,又出現(xiàn)一個錯誤,提示如下:
SQL Server 阻止了對組件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的訪問,因為此組件已作為此服務器安全配置的一部分而被關閉。系統(tǒng)管理員可以通過使用 sp_configure 啟用 'Ad Hoc Distributed Queries'。有關啟用 'Ad Hoc Distributed Queries' 的詳細信息,請參閱 SQL Server 聯(lián)機叢書中的 "外圍應用配置器".
解決方法如下:
啟用Ad Hoc Distributed Queries方法:
exec sp_configure 'show advanced options',1
go
reconfigure
go
exec sp_configure 'Ad Hoc Distributed Queries',1
go
reconfigure
go
關閉Ad Hoc Distributed Queries方法:
exec sp_configure 'Ad Hoc Distributed Queries',0
go
reconfigure
go
exec sp_configure 'show advanced options',0
go
reconfigure
go
啟用Ad Hoc Distributed Queries后,再次運行程序,正常!