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();
            }
        }

 

相关文章:

  • 2022-12-23
  • 2021-08-15
  • 2021-12-18
  • 2021-07-12
  • 2021-10-14
  • 2022-01-26
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-23
  • 2022-02-20
  • 2021-12-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案