Integer result
oleobject loo_sqlserver
loo_sqlserver = Create oleobject
result = loo_sqlserver.ConnectToNewObject("SQLDMO.SQLServer")
If result <> 0 Then
// messagebox('提示','创建OLE对象时产生错误')
Return False
Else
loo_sqlserver.Name = server
If loo_sqlserver.status = 1 Then
loo_sqlserver.DisconnectObject()
Destroy loo_sqlserver
Return True
ElseIf loo_sqlserver.status = 3 Then //服务停止
loo_sqlserver.Start(False,server,'sa','')
ElseIf loo_sqlserver.status = 2 Then //服务暂停
loo_sqlserver.Continue()
End If
//启动之后再次判断是否成功-延时等待SQLSERVER启动
Sleep(6000)
If loo_sqlserver.status = 2 Or loo_sqlserver.status = 3 Then
// messagebox('错误','启动服务失败')
Return False
End If
End If
loo_sqlserver.DisconnectObject()
Destroy loo_sqlserver
Return True
查看有哪些数据库可以先连接上master
然后查看表
sysdatabases 这个表里存的数据库的信息/
判断有没有安装sqlserver,可以直接查看一下注册表
HKEY_LOCAL_MACHINE
SOFTWARE/Microsoft/MSSQLSERVER/setup
SQLPath
看看键值存不存在