//判断SQL Server是否已经启动,如果没有启动则做相应处理
st_status.text='判断SQL Server是否已经启动 ...'
OLEObject PBObject
long ll_status
PBObject = CREATE OLEObject
ll_status = PBObject.ConnectToNewObject ("SQLDMO.sqlserver")
string ls_serverName
integer li_Return
string ls_UserName
String ls_Password
Constant Integer SQLDMOSvc_Unknown =0//未知状态
Constant Integer SQLDMOSvc_Running =1//已经启动
Constant Integer SQLDMOSvc_Paused =2//SQL Server为暂停状态
Constant Integer SQLDMOSvc_Stopped =3//SQL Server为停止状态
Constant Integer SQLDMOSvc_Starting =4//SQLSERVER正在启动(关闭-->启动)
Constant Integer SQLDMOSvc_Stopping =5//SQLSERVER正在关闭
Constant integer SQLDMOSvc_Continuing=6//SQLSERVER正在启动(暂停-->启动)
Constant Integer SQLDMOSvc_Pausing =7//SQLSERVER正在暂停(启动-->暂停)
ls_ServerName='218.71.42.229'
ls_UserName='sa'
ls_password=''
IF ll_status = 0 THEN //连接成功
PBObject.name = ls_servername
PBObject.logintimeout=10
PBObject.LoginSecure = True //以NT方式连接
//PBObject.LoginSecure = false //以SQL Server方式连接
IF isNull(PBObject) Then Return
Try
li_return = PBObject.Status
Catch(RunTimeError rte)
Messagebox("提示","没有安装SQLServer",StopSign!)
End try
Choose case li_return
case 1 //已经启动
st_Status.text=ls_ServerName+'已经启动SQLSERVER服务器'
//PBObject.stop()//停止SQLSERVER
case 2 //SQL Server为暂停状态
st_status.text = '启动' + ls_servername + '上的SQL Server ...(暂停-->启动)'
PBObject.Continue()
case 3 //SQL Server为停止状态
st_status.text = '启动'+ ls_servername + '上的SQL Server ...(停止-->启动)'
PBObject.Start(false,ls_servername,ls_username,ls_password)//启动SQL Server
case 4 //SQLSERVER正在启动(关闭-->启动)
st_status.text = ls_servername + '上的SQL Server 正在启动(关闭-->启动)'
PBObject.start(false,'sa','')//停止SQLSERVER
case 5 //SQLSERVER正在关闭
st_status.text = ls_servername + '上的SQL Server 正在关闭'
case 6 //SQLSERVER正在启动(暂停-->启动)
st_status.text = ls_servername + '上的SQL Server 正在启动(暂停-->启动)'
case 7 //SQLSERVER正在暂停(启动-->暂停)
st_status.text = ls_servername + '上的SQL Server 正在暂停'
case 0 //未知状态
st_status.text = '未知'+ls_servername + '上的SQL Server 状态'
End Choose
ELSE
messagebox("系统提示","数据库连接失败!~n请检查输入的用户名和口令是否正确")
return
end if
Destroy(PBObject)