public static void ReStartSQLServive()
{
string myServiceName = "MSSQL$SQLEXPRESS"; //service name of SQL Server Express
ServiceController mySC = new ServiceController(myServiceName);
try
{
if (!mySC.Status.Equals(ServiceControllerStatus.Stopped))
{
mySC.Stop();
mySC.WaitForStatus(ServiceControllerStatus.Stopped);
}
mySC.Start();
mySC.WaitForStatus(ServiceControllerStatus.Running);
}
catch (Exception)
{
return;
}
}
//但是重新啟動服務之後,要等將近一分鐘才能夠正常連線,這點很奇怪
沒有留言:
張貼留言