A little while ago, I came across this issue at one of my clients. They needed the SharePoint Instance of the MSSQL server to restart at 5 am every morning. That seemed like a fair task to fix pretty easily. It turns out though, that the prompt, asking the user, if he/she is sure about stopping the service.
Like I would ever do anything without being sure.. sigh!
Anyway, I dug around and found that I had to build a little strange solution in order for this to run 100% automatically.
To avoid this question ever time you restart your service you need to:
- Create a folder c:\CustomSolutions\RestartMSSQL
- Create a file called c:\CustomSolutions\RestartMSSQL\y.txt, which contains ONLY the letter y and a carrige return (type “y” and hit enter)
- Create a c:\CustomSolutions\RestartMSSQL\restartsql.bat file which contains:
net stop MSSQL$SharePoint /y < “c:\CustomSolutions\RestartMSSQL\y.txt” && net start MSSQL$SharePoint /y < “c:\CustomSolutions\RestartMSSQL\y.txt”
- Create a scheduled task that runs that batch file whenever you need. Remember to set the scheduled task to run even if the user is not logged in.
This is the actual Best Practice on how to do this. I got the solution of technet somewhere. It is beyond me, why this hack is necessary. Why isn’t there a flag I can set somewhere to avoid that stupid y.txt file? It works perfectly, but I would rather just script it all in my batch script.
If you have another way of doing this, please leave a comment to educate me. There has to be a better way of doing this.