I am writing a test class. In this class, I need to stop the sql server in Setup() method, and restart the sql server in Teardown() method. I don't know how to stop or start the sql server in c#. anyone can help me ?
thx in advance~
I am writing a test class. In this class, I need to stop the sql server in Setup() method, and restart the sql server in Teardown() method. I don't know how to stop or start the sql server in c#. anyone can help me ?
thx in advance~
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
surendra kumarPosted Jan 8, 2008, 2:26 AM
Blocked AccountPosted Jan 8, 2008, 1:52 AM
First u have to add the reference of the System.ServiceProcess.dll and after that create the object of the ServiceController like this:
ServiceController objServiceController = new ServiceController("MSSQLSERVER");
For start the server write this:
objServiceController.Start();
For stop the server write this:
objServiceController.Stop();