解决问题
SQL Server 阻止了对组件 'xp_cmdshell' 的 过程 'sys.xp_cmdshell' 的访问,因为此组件已作为此服务器安全配置的一部分而被关闭。系统管理员可以通过使用 sp_configure 启用 'xp_cmdshell'。有关启用 'xp_cmdshell' 的详细信息,请参阅 SQL Server 联机丛书中的 "外围应用配置器"。
解决思路
出现这种错误是因为使用bcp命令的时候,没有权限。SQL Server的用户没有SP_configure的使用权限,需要将对应用户添加"sysadmin"角色。所以,要首先启动该命令。
解决方法
sp_configure 'show advanced options',1
reconfigure
go
sp_configure 'xp_cmdshell',1
reconfigure
go
大功告成!
EXEC master..xp_cmdshell 'bcp "use CV_data SELECT * FROM CV_data.ChinaWealthList ORDER BY name" queryout "C:\Users\99386\Desktop\book1.xls" /c -/S"localhost" /U"sa" -P"sasa"'