6/15/2015

Starting and Stopping MS SQL Server from bat file

Start SQL Server:
@echo off

sc query "MSSQL$SQL01" | find /I "STATE" | find "STARTED"
if errorlevel 1 goto :start
goto :end

:start
net start "MSSQL$SQL01"
net start "SQLAgent$SQL01"
rem net start "MSSQLFDLauncher$SQL01"
net start "SQLBrowser"
net start "SQLWriter"

:end
Stop SQL Server:
@echo off

sc query "MSSQL$SQL01" | find /I "STATE" | find "STOPPED"
if errorlevel 1 goto :stop
goto :end

:stop
net stop "SQLAgent$SQL01"
net stop "MSSQL$SQL01"
net stop "MSSQLFDLauncher$SQL01"
net stop "SQLBrowser"
net stop "SQLWriter"

:end
Start/Stop SQL Server in cycle:
@echo off

sc query "MSSQL$SQL01" | find /I "STATE" | find "STOPPED"
if errorlevel 1 goto :stop
goto :start

:stop
net stop "SQLAgent$SQL01"
net stop "MSSQL$SQL01"
net stop "MSSQLFDLauncher$SQL01"
net stop "SQLBrowser"
net stop "SQLWriter"

goto :end

:start
net start "SQLAgent$SQL01"
net start "MSSQL$SQL01"
rem net start "MSSQLFDLauncher$SQL01"
net start "SQLBrowser"
net start "SQLWriter"

:end

No comments:

Post a Comment