Solved

How to restart SQl server automatically

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

758 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

19 Experts available now in Live!

Get 1:1 Help Now