当前位置:Gxlcms > 数据库问题 > C# 启动 SQL Server 服务

C# 启动 SQL Server 服务

时间:2021-07-01 10:21:17 帮助过:69人阅读

//首先要添加 System.ServiceProcess.dll 引用 2 ServiceController sc = new ServiceController("MSSQLSERVER"); 3 4 //判断服务是否已经关闭 5 if (sc.Status == ServiceControllerStatus.Stopped) 6 { 7 sc.Start(); 8 MessageBox.Show("SQL数据库服务启动成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); 9 } 10 11 //判断服务是否已经开启 12 if (sc.Status != ServiceControllerStatus.Stopped) 13 { 14 sc.Stop(); 15 MessageBox.Show("SQL数据库服务成功关闭!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); 16 } View Code

 

C# 启动 SQL Server 服务

标签:alt   show   span   close   添加   技术分享   serve   dll   分享   

人气教程排行