C# 启动 SQL Server 服务的实例
时间:2020-12-12 14:05:01|栏目:.NET代码|点击: 次
实例如下:
//首先要添加 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);
}
上一篇:在ASP.NET 2.0中操作数据之十七:研究插入、更新和删除的关联事件
栏 目:.NET代码
下一篇:使用C#在注册表中保存信息的例子
本文地址:http://www.codeinn.net/misctech/32111.html






