C# 启动 SQL Server 服务


 1  //首先要添加 System.ServiceProcess.dll  引用
 2             ServiceController sc = new ServiceController("MSSQLSERVER");
 3 
 4             //判断服务是否已经关闭
 5             if (sc.Status == ServiceControllerStatus.Stopped)
 6             {
 7                 sc.Start();
 8                 MessageBox.Show("SQL数据库服务启动成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
 9             }
10 
11             //判断服务是否已经开启
12             if (sc.Status != ServiceControllerStatus.Stopped)
13             {
14                 sc.Stop();
15                 MessageBox.Show("SQL数据库服务成功关闭!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
16             }
View Code

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM