软件编程
位置:首页>> 软件编程>> C#编程>> C# 启动 SQL Server 服务的实例

C# 启动 SQL Server 服务的实例

作者:yuchen_love  发布时间:2022-02-10 21:59:38 

标签:C#,启动,SQLServer,服务

实例如下:


//首先要添加 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);
  }

来源:http://www.cnblogs.com/yuchenlove/archive/2017/12/01/7940413.html

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com