views:

158

answers:

2

The issue I'm running into is that I don't always have access to the server but I need to restart the database on the server. Is this possible if so how would I do this?

I know you can start and stop a named instance from cmd from the server. Not sure how to do from client.

+1  A: 

SC is built-in command line utility on Windows platform that can be used for your requirement. Here is brief description of the same.

The SC executable can be used to start the SQL Server services locally or on a remote machine. The SC executable is a command line program that can be used to communicate with the NT Service Controller and services. This exe has lots of functionality. Not only can you start and stop your SQL Server services, but you can also use this exe to create and manage your services. In the scope of this article, I will only cover how you can use this exe to start and stop your SQL Server services. Here is the syntax for calling the sc executable:

sc [ServerName] Command ServiceName [ServiceArguments]ServerName Specifies the name of the server where the service will be started or stopped. Enter the ServerName in UNC format ("\myserver"). ServerName is not needed if you are stopping/starting a local service. Command The command is either “start” or “stop”. ServiceName The service name to be started or stopped. ServiceArguments Specifies service arguments to pass to the service being started. Note: this option is not used when the command “stop” is issued.

You can pass information about user account and password through sc command.

sc \ServerName start ServiceName obj=[Account] password=[password]

You can find detailed information regarding sc command on this link Microsoft KB for SC.EXE

Rutesh Makhijani
he didnt say whether or not he used Windows 2000. if he uses windows 2000 then he wont have sc.exe .
djangofan
I used the sc.exe that worked from the command prompt now I'm trying to write this in C# but running into problems when I place "start /Wait " in front of SC. Here is an example.strCommandStop1 = @"start /wait sc " + strServer + " Stop " + strDb1; strCommandStop2 = @"start /wait sc " + strServer + " Stop " + strDb2;ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.Arguments = strCommandStop1; startInfo.Arguments = strCommandStop2; startInfo .FileName = "sc.exe"; Process.Start(startInfo);
Jason
A: 

Well, if you want a command that does it, then that "implies" that you actually have network access to the machine. That being the case, just right click on "My Computer", choose Manage, then choose "Connect to remote machine" then start it from there. To do it that way you might need to have the service registered to run as your account.

Im not so sure that "net start" would do the job here but it is possible that there is a way using Powershell if you are using XP/Vista/Windows7.

djangofan