實例如下:
//首先要添加 System.ServiceProcess.dll 引用 ServiceController sc = new ServiceController("MSSQLSERVER"); //判斷服務是否已經關閉 if (sc.Status == ServiceControllerStatus.Stopped) { sc.Start(); MessageBox.Show("SQL數據庫服務啟動成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } //判斷服務是否已經開啟 if (sc.Status != ServiceControllerStatus.Stopped) { sc.Stop(); MessageBox.Show("SQL數據庫服務成功關閉!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); }
以上這篇C# 啟動 SQL Server 服務的實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持VEVB武林網。
新聞熱點
疑難解答