Skip to content
Menu
莱风 莱风
  • 序章
莱风 莱风

使用xp_cmdshell重启SQL server服务

Posted on 2021/05/242024/02/13 by zhou
--开启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'

发表回复 取消回复

您的邮箱地址不会被公开。 必填项已用 * 标注

3 + 0 = ?

近期文章

  • redhat Linux centos7 安装或卸载官方MySQL8
  • WordPress文章游客评论时添加验证码
  • 宝塔面板MySQL设置单数据库主从双向同步
  • wordpress修改底部版权信息删除RSS订阅按钮
  • centos7安装sql server 2022

分类

  • docker (4)
  • Linux (2)
  • MySQL (1)
  • sql (8)
  • Windows (5)
  • WordPress (5)
  • 未分类 (11)
  • 飞跃长城 (5)

近期评论

    其他操作

    • 登录
    ©2025 莱风