通過SQLSERVER重啟SQLSERVER服務(wù)和計算機的方法
發(fā)布日期:2022-01-28 11:20 | 文章來源:CSDN
希望可以給大家一些幫助吧,呵呵
首先在本地計算機--創(chuàng)建重啟腳本
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'
通過SQL數(shù)據(jù)庫連接到遠程服務(wù)器--執(zhí)行重啟腳本
exec master..xp_cmdshell 'c:\restart.bat' /*
如果重新啟動計算機,請確認mssqlserver賬戶在管理員賬戶下運行(非本地系統(tǒng)賬戶) */ exec master..xp_cmdshell 'shutdown /r /f' 這里有個前提,那就是需要用到服務(wù)器上的一個組件,xp_cmdshell這個組件,但是一般的服務(wù)器, 這個組件都是被禁用的。所以要先起用組件才可以應(yīng)用上面的方法。
復(fù)制代碼 代碼如下:
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'
通過SQL數(shù)據(jù)庫連接到遠程服務(wù)器--執(zhí)行重啟腳本
exec master..xp_cmdshell 'c:\restart.bat' /*
如果重新啟動計算機,請確認mssqlserver賬戶在管理員賬戶下運行(非本地系統(tǒng)賬戶) */ exec master..xp_cmdshell 'shutdown /r /f' 這里有個前提,那就是需要用到服務(wù)器上的一個組件,xp_cmdshell這個組件,但是一般的服務(wù)器, 這個組件都是被禁用的。所以要先起用組件才可以應(yīng)用上面的方法。
版權(quán)聲明:本站文章來源標注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。
相關(guān)文章