源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

C# 启动 SQL Server 服务的实例

  • 时间:2022-03-22 05:50 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:C# 启动 SQL Server 服务的实例
[b]实例如下:[/b]
//首先要添加 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 服务的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编程素材网。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部