Solved

How to restart SQl server automatically

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Auditing with Temporal Tables 4 29
Creating Alerts in sql sever 2 25
Upgrading Integration Services 3 28
SQL Server - SQL field is defined as text 3 25
Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

947 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now