Solved

How to restart SQl server automatically

Posted on 2010-08-27
4
811 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 143

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.

861 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