batch file - Check if SQL server service is running -


currently facing problem effects system stability, our server has sql server 2012 , unknown reason services stop running , needs restart manually every single day. have created command in batch file restart sql server automatically , works fine, however, looking better command can check if sql server stop, restart it, if running, ignore. how can command ?

@echo off net start mssql$sqlexpress 

something this. pause optional. don't use if goes in scheduled task! in case wouldn't need echo statements either. of course need run administrative privileges start service. added check that.

@echo off set "service=mssql$sqlexpress" rem make sure service exists sc query %service% | (findstr "does not exist" && goto :done)  /f "tokens=1,2,3,4" %%a in ('sc query %service%') (    if /i %%a == state (       if /i not %%d == running (          echo(%service% state %%d.  should running.          rem openfiles requires admin          openfiles >nul 2>&1 || (color e0 & echo(you must run administrative priveleges start service. & goto :done)          echo(starting now...          sc start %service%          )       )    ) :done pause 

might idea through windows event log , see if can determine why service stopping, there wrong.


Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -