我是这样写的:
private void btnTest_Click(object sender, EventArgs e)
{ ServiceController sc = new ServiceController("MSSQLSERVER");
if (sc.Status.Equals(ServiceControllerStatus.Stopped))
{
sc.Start();
}
} private void button1_Click(object sender, EventArgs e)
{
ServiceController sc = new ServiceController("MSSQLSERVER");
if (sc.Status.Equals(ServiceControllerStatus.Running))
{
sc.Stop();
}
}
我的机器上有SQL2000和2005,这里默认的直接去找2000,我把new ServiceController("MSSQLSERVER");
改成了new ServiceController("(local)\SQLEXPRESS")不过还是不对,提示是“在计算机“.”上没有找到服务(local)\SQLEXPRESS”
怎么才能使他去测试2005呢?谢谢大家帮帮忙。
private void btnTest_Click(object sender, EventArgs e)
{ ServiceController sc = new ServiceController("MSSQLSERVER");
if (sc.Status.Equals(ServiceControllerStatus.Stopped))
{
sc.Start();
}
} private void button1_Click(object sender, EventArgs e)
{
ServiceController sc = new ServiceController("MSSQLSERVER");
if (sc.Status.Equals(ServiceControllerStatus.Running))
{
sc.Stop();
}
}
我的机器上有SQL2000和2005,这里默认的直接去找2000,我把new ServiceController("MSSQLSERVER");
改成了new ServiceController("(local)\SQLEXPRESS")不过还是不对,提示是“在计算机“.”上没有找到服务(local)\SQLEXPRESS”
怎么才能使他去测试2005呢?谢谢大家帮帮忙。
还是不行,也是提示“在计算机“.”上没有找到服务SQLEXPRESS”
if (sc.Status.Equals(ServiceControllerStatus.Running))
{
sc.Stop();
}
} 测试通过
右键查看显示属性里面有个显示名称直接copy过来就ok了
也谢谢大家了
http://topic.csdn.net/u/20090114/09/1c6425ef-b2af-4fae-927f-94f680a2e8ee.html