--开启xp_cmdshell
EXEC sp_configure 'show advanced options', 1
GO
-- 重新配置
RECONFIGURE
GO
-- 启用xp_cmdshell
EXEC sp_configure 'xp_cmdshell', 1
GO
--重新配置
RECONFIGURE
GO
--开启Ole Automation Procedures
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Ole Automation Procedures', 1;
GO
RECONFIGURE;
GO
--重启SQL server服务
declare @o int,@f int,@t int,@ret int
exec sp_oacreate 'scripting.filesystemobject',@o out
exec sp_oamethod @o,'createtextfile',@f out,'c:\restart.bat',1
exec @ret=sp_oamethod @f,'writeline',NULL,'net stop mssqlserver'
exec @ret=sp_oamethod @f,'writeline',NULL,'net start mssqlserver'
--执行重启脚本
exec master..xp_cmdshell 'c:\restart.bat'