检查是否已安装SQL
我已安装了SQL,可还是提示:此计算机未安装SQL软件,请安装SQL后再试代码如下
private void start_Load(object sender, EventArgs e)
{
if (exitSQL())
{
timer1.Start();
}
else
{
MessageBox.Show("此计算机未安装SQL软件,请安装SQL后再试", "SQL错误提示", MessageBoxButtons.OK);
Application.Exit();
}
}
public bool exitSQL()
{
bool sqlflag = false;
ServiceController[] services = ServiceController.GetDevices();
for (int i = 0; i < services.Length; i++)
{
if (services[i].DisplayName.ToString() == "MSSQLSERVER")
{
sqlflag = true;
}
}
return sqlflag;
}