Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stop the SQL SERVER using script 2

Status
Not open for further replies.

password99

Technical User
Jul 19, 2002
122
US
is there a away to stop the SQL SERVER as a batch process (under scheduled task) and to restart it.
 
May I ask why you want to do this? If it is for taking a backup of the system, I would use the Database Maintenance Planner option on the Tools menu in Enterprise manager for this, as otherwise you risk corruption of data in your databases (you cannot check who is logged onto the system via a batch file).

John
 
Yes, the reason is that we want to back up the folder in which the Database file resides and we cannot back up if SQL Server is running.
 
Can't you stop and start SQL Server in a batch file by using:

NET STOP [service]
NET START [service]

I'm not sure what the SQL Server service name is called...

Andy
 
thanks

i need to stop the named instance sqlserver using batch file...is there something to stop a named instance using net stop?
 
Andy

You can do it that way, but please take note that this takes no note of the fact that there may be uncommitted data around or users logged on at the time.
Therefore, this is a very poor method of doing it.

A far better approach is to use the SQL Server database maintenance plan wizard to set this up to back up to an external file, which you can then get copied to your tape drive or whatever backup device you use.

John
 
>> A far better approach is to use the SQL Server database maintenance plan wizard to set this up to back up to an external file, which you can then get copied to your tape drive or whatever backup device you use.

And an even better approach is to code a backup command which you schedule.

The time that you are likely to lose your database is when the server is stopped and started - which will mean that your file backups are useless too so you will go back to the prevoius ones.
Means you also can't have diffs or log backups and also can never run a 24x7 service (and suffer the derision of your peers :)).

======================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
 
As a side note ... When you stop the SQL Server service and then restart it, you will also need to restart the SQL Server Agent Service as well. SQL Server Agent does not automatically restart when the SQL Server service starts.

There are ways to have the SQL Server Agent start automatically when the SQL Server service starts if you are interested.

Thanks

J. Kusch
 
e.g.

create proc StartAgent
as
waitfor delay '00:05:00' -- wait 5 mins
exec master ..xp_cmdshell 'net start sqlserveragent'
go

exec sp_procoption 'StartAgent', 'startup', 'on'


======================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top