March 23, 2014 at 11:52 pm
How can i best issue an sql query and also restart a windows service from a remote machine?
“When I hear somebody sigh, ‘Life is hard,’ I am always tempted to ask, ‘Compared to what?’” - Sydney Harris
March 24, 2014 at 8:57 am
Powershell?
What query are you attempting to run? And are you asking to restart a windows service on an external machine via TSQL?
______________________________________________________________________________Never argue with an idiot; Theyll drag you down to their level and beat you with experience
March 24, 2014 at 10:48 am
kapfundestanley (3/23/2014)
How can i best issue an sql query and also restart a windows service from a remote machine?
My first temptation is to issue a wiseacre answer like:
1. SSMS
2. Control Panel > Administrative Tools > Services > Connect to another computer
But seriously...
1. Are you trying to do both from a scripted situation, such as a scheduled task?
2. If so have you considered a batch script running osql for the SQL and then a SC \\[machinename] STOP and SC\\[machinename] START
Thanks
John.
March 25, 2014 at 1:21 am
Yes ,I have managed to do a batch script:
sqlcmd -i C:\scripts\C2.sql
sc \\servername stop Servicename
sc \\servername start Servicename.
This is working if I want to run script ,start and stop service on the same server.When the server to run script and start/stop service is different the batch script is not working.
“When I hear somebody sigh, ‘Life is hard,’ I am always tempted to ask, ‘Compared to what?’” - Sydney Harris
March 26, 2014 at 3:33 am
You need to tell SQLCMD which server to connect to in order to run the script you're passing it--you do that with the -S parameter (note that's a capital S, lowercase s does something else). You may also need to supply a username and password (using -U and -P) depending on the situation.
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy