c# 启动关闭sql服务
static void Main(string[] args) { ServiceController sc = new ServiceController("MSSQL$SQLEXPRESSR2"); while (1 == 1) { Console.Write("\n\n 可选操作 : \n\n 1.启动数据库服务 2.停止数据库服务 \n\n 开始执行 :"); string strQueryState = Console.ReadLine(); if (strQueryState.Trim() == "1" && sc.Status.Equals(ServiceControllerStatus.Stopped)) { sc.Start(); Console.Write("SQL数据库服务启动成功!"); } else if (strQueryState.Trim() == "2" && !sc.Status.Equals(ServiceControllerStatus.Stopped)) { sc.Stop(); Console.Write("SQL数据库服务停止成功!"); } sc.Refresh(); } }
作者:三小
声明:原创博客请在转载时保留原文链接或者在文章开头加上本人博客地址,如发现错误,欢迎批评指正。凡是转载于本人的文章,不能设置打赏功能,如有特殊需求请与本人联系!