Solved

How to restart SQl server automatically

Posted on 2010-08-27
4
802 Views
Last Modified: 2012-06-27
I need a batch file or a script that can automatically start/stop SQL server (default instance), once every day. I tried "net stop mssqlserver", but when the batch file executes it ask for user input for yes/no, etc. I assume I need to add some switches..

I need to do this to clrear the tempdb once a day... because it's growing too big , and I don't have time to trace the problem.
0
Comment
Question by:techzone12
4 Comments
 

Author Comment

by:techzone12
ID: 33543817
I created a batch file as follows:
net stop mssqlserver
net start mssqlserver

When I run the batch file, I am getting this message:

Restarting SQL server ...
The following services are dependent on the SQL Server (MSSQLSERVER) service.
Stopping the SQL Server (MSSQLSERVER) service will also stop these services.

   SQL Server Agent (MSSQLSERVER)

Do you want to continue this operation? (Y/N) [N]:

I want the batch file to run without user input.  Also is stopping this service will have impact on other services. Do they have to be restarted too?
0
 
LVL 10

Expert Comment

by:pai_prasad
ID: 33545596
you need to stop SQL Server Agent first and then MSSQLServer.
do this..


net stop SQLSERVERAGENT
net stop MSSQLServer

net start MSSQLServer
net start SQLSERVERAGENT

0
 
LVL 4

Expert Comment

by:MSSystems
ID: 33545604
Please try this
call net stop SQLSERVERAGENT
call net stop MSSQLSERVER
call net start SQLSERVERAGENT
call net start MSSQLSERVER
pause

Open in new window

0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 33546196
easier for  the "stop":http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/net_command_options.mspx?mfr=truenet stop MSSQLSERVER /yhowever, you will indeed need to start all the dependencies "by hand" anyhow, so you need to know (and keep the list updated) anyhow.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question