Friday, January 21, 2011

Using C# Start/Stop Sql Server Services

Following Code will help for starting and stoping Sql Server Services using C#
Code

Sample Code:

ServiceController service = new ServiceController("MSSQL$SQLEXPRESS");//Check sqlexpress service running.
//Sql Serverservice how to stop
if (service.Status == ServiceControllerStatus.Running)
{
service.Stop();
service.Refresh();
}
//Sql Serverservice how to start
if (service.Status == ServiceControllerStatus.Running)
{
service.Stop();
}
}

No comments: