C#教程

关注公众号 jb51net

关闭
首页 > 软件编程 > C#教程 > C# 启动 SQL Server 服务

C# 启动 SQL Server 服务的实例

作者:yuchen_love

下面小编就为大家分享一篇C# 启动 SQL Server 服务的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

实例如下:

//首先要添加 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 服务的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:
阅读全文